Accessing Application Scope from an EJB

I'm not sure of the best way of doing this:
The set up:
We have a rather large J2EE application that is composed of only servlets and JSPs at the moment (When the application began development EJB was in its infancy and not feasible for the development of the app). Some of the new deployments of the app involve distributed webserver over 4 JVMs and 2 machines. When a user connects the servers load balancing decides which particular JVM they should be connected to. We perform large data caching into the servlet application scope to avoid having to access the database every time a change is made by a user to certain tables in our database. The data caches are stored in hashtables in the servlet application scope.We seem to have no way to determine what other JVMs are running or which JVM a user is currently connected to.
The problem:
Apparently the application scope is for a particular JVM. This means that when a user makes a change to a data cache the change doesn't effect users in the other 3 JVMs of the application, only the users who, due to load balancing, happened to be connected to the same JVM as the one where the change was made.
Our possible solution:
We were thinking that we could set up a queue (such as MQSeries from IBM) and any time a change is made to one of these data caches put a message on the stack saying that the particular table had been updated. Then a MDB would be listening asynchronously and digest the message from the Queue and recache the tables from the database.
So here are my questions:
1. Would this work? Would putting a MDB in the EJB Container give each JVM the MDB in the first place, or would this mean it would pick one of the JVMs to deploy the MDB on and still not fix our problem.
2. If this does work, how do I access the hashtables stored in the Servlet Application scope from the MDB. I can't seem to find any method available to the MDB (or any EJBs for that matter) that can access the servlets Application scope.
3. Is this the best way to do this? Or is there a better way to share data between seperate JVMs that I don't have a URL to (It's all ambiguous and handled by the server as to which JVM actually gets the connection.)
Just in case this is needed:
We are running IBM WebSphere 5 Application Server and the database could be anything from DB2 to Oracle.
Thanks in advance for any possible help.

You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

Similar Messages

  • ACCESSING APPLICATION SCOPE FROM FILTERS

    HI
    Is there any way to access the application scope from inside security filters? i have a class that implements the Filter interface and i'm trying to access the application scope in the doFilter method.
    The FacesContext Object is null, and i'm only able to access the session scope using request.getSession()
    I want to check for global application properties that are saved in the application scope.
    Thanks

    thank you BalusC it's working

  • Application scope bean Vs. EJB

    I want to cash some application data - and was thinking of using a singleton bean with application scope in my controller and JSP page.
    <jsp:useBean id="myBean" scope="application" class="bean.datacash" />
    I am not very familiar with EJBs - and wanted to know if it would be a mistake not to use an EJB to perform that task.
    Is there a downside to my approach?
    Thanks for any insight
    Mike

    Entity EJB'S are used as a kind of data persistence, mostly to Databases. In a way it's like a kind of cache but any changes you make to an EJB are usually persisted to the underlying data storage on a regular basis.
    Session EJB's are more for business logic and depending on the type of Session Bean you use can either remain persisted in a session state or used and thrown away.
    EJB's also require alot of code so depending on your application requirements it is kind of a big decision.
    Is the data your wanting to cache to be shared by all users using the application? Are there any race conditions that may be met by concurrent access to the data? What do you plan to do with the cached data store it in a database or just make it available to share?
    If you want to look into using EJB's then your going to require an EJB Container to run them in (this can be standalone like OpenEJB or as part of an J2EE Application server like JBoss or Oracle Application Server to name just a couple).
    Using the Singleton Javabean can keeps things simple but once you start to synchronize methods with multiple users you can find some slowing down of the logic as the singleton tries to complete a request before getting onto the next.
    The [url http://jakarta.apache.org]Jakarta team offer a package called commons pooling which is designed as a pooling framework (also a way of caching) that can come in handy, I've used it to create a custom JDBC Connection pooler and it works quite well when you get the hang of it.
    Another thing to consider is the load the application may be under at it's busiest time. How many concurrent users do you expect to access the application?
    Sorry I can't give you a real answer as that is entirely up to you and your requirements. If you have a small app that has around 20-50 users then EJBs are bit of an overkill. If you find you'll have 100+ users with lots of data to manage then EJB's are probably a good option.
    If you have a look at [url http://www.theserverside.com]the serverside web site you may find a couple of articles on data persistence or check out some of the online magazines which also have articles on this same topic.
    Anthony

  • Can you write Application.log from an EJB?

    I can write to my EAR's Application.log file from a servlet using the ServletContext's log method. But I can't find a way to do the same from an EJB. Anyone know if it's possible?

    Yes have a read of - Working with Plan Types
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Accessing EnvironmentProperty entries from an EJB

    Does anyone know how to access environment entries from within an EJB? One of the examples in the ejb/corba devguide contains the following:
    // Add any environment properties that
    // the bean requires
    EnvironmentProperties {
    prop1 = "value1";
    prop2 = "value two";
    Yet there are no examples or instructions on how to access them anywhere in the document, nor in any of the other Java documents, that I've found.
    I've tried the following from within my ejb:
    Context Initial = new InitialContext();
    String prop1 = (String)initial.lookup("prop1");
    This does not work. Neither does a string of the form "java:comp/env/prop1".
    Anybody know how to access these properties?
    Cheers,
    ax
    null

    In answer to my own question, use the SessionContext getEnvironment() method.
    ax
    null

  • How to access application state from stateless web service?

    I have a beginner J2EE question. After reading through J2EE tutorial, I still don't know how to create an application that would run on J2EE server, and which would have a web service interface to other world, and which would have several threads running, which would connect to other enterprise applications via TCP? Because if I understand it correctly, web service requires a stateless session bean, which means that it can't access any stateleful session bean (except always create one and remove it instantly). So there seems to be no way to store application state and have running threads.
    I'm asking this because .NET seems to have a very simple Application dictionary, which can save all application objects, including threads, and it is very easy to access this Application state from a stateless web service. Isn't there any similar functionality in J2EE? And if not, how it should be done in Java world then?
    I guess that the Connector architecture could be the solution, but it is not documented in the tutorial.

    There's nothing in the J2EE spec that says that you have to use Web Services. Web Services by definition are stateless.
    If your requirements are that you have to use a session bean along with a Web Service, then the architecture needs to be rethought, because it doesn't seem to me that Web Services are what you want.
    That said, you can use a hybrid. You can expose some of the functionality of your application as Web Services while the remaining is implemented in a classic J2EE type framework that is stateful.
    I would also think that you could store your application state via entity beans. You could save and load them when the web service is accessed. An entity bean doesn't require a database... just some form of persistence (could be an XML file for instance).
    You need to decide which components of J2EE make sense when and where.

  • Cannot Access Application Module from View Project (Swing)

    I recently started a new application workspace as a Swing project with Business Components. Jdev created 2 projects by default, a Model and a View. The model works fine, all the business components are funtctioning and the DB connection is good. When i try to create a reference to the application module in my View project i constantly get 'Class Not Found' exceptions no matter what i do. I am using the jbo.client.Configuration.getRootApplicationModule('amName', 'amConfig') method.
    What am i missing? How do i instantiate my application module from my View project?
    Thanks a lot.

    Just had to add the Model to the classpath...

  • How to access application module from ActionForm Execute?

    I've got a very simple ADF/UIX/Struts application where I'm trying to create a simple Login function. I have a /loginAction data action pointing to a login.uix page forward. The login.uix page has a <struts:form> on it with a user and a password field. There is a LoginBean with the corresponding get/set values. I have an ADF model created with a boolean login(String username, String password) function exposed as a client method.
    Eventually, when I have this basic part working, then I'll actually be using an ActionForward mapping to dispatch to different home pages, based on the particular login account (the name of the forward will be stored in the authentication table).
    I've tried overriding Execute(), since that is where you can return the appropriate ActionForward mapping, but that does not have a DataActionContext passed in -- so I can't get to the application module.
    I've also looked at processComponentEvents, but that doesn't have any ActionForward results nor a way to pass back ActionErrors (in case the login fails).
    How do I call my login client method when a user has entered a username/password and pressed the Submit button?

    Here is another solution as provided by Oracle Support in response to a TAR that I opened:
    I had described my need to access a login() function defined in my Application Module, returning true/false if the login succeeds/fails. Here is the reply, posted with permission:
    I have gotten the following information back from one of the development folks pertaining to the question you asked.
    His suggestions are as follows:
    1) Expose the method as a client method on the App module
    2) On the pageflow create a new DataAction
    3) Drag and drop the logon method from the AppModule operations node and drop it onto the new data Action
    3) Edit the set-property values that are created in the Struts metadata for this new DataAction to use the correct expressions to get the logon info to pass to the middle tier.
    e.g.
    <action path="/authenticateUser" className="oracle.adf.controller.struts.actions.DataActionMapping" type="AuthenticateUserAction" name="DataForm"
    unknown="false">
    <set-property property="modelReference" value="authenticateUserUIModel"/>
    <set-property property="methodName" value="authenticateUserUIModel.authenticateUser"/>
    <set-property property="resultLocation" value="${requestScope.methodResult}"/>
    <set-property property="numParams" value="2"/>
    <set-property property="paramNames[0]" value="${param.logonUsername}"/>
    <set-property property="paramNames[1]" value="${param.logonPassword}"/>
    <forward name="fail" path="/logon.do"/>
    <forward name="success" path="/menu.do"/>
    </action>
    So in this case the values of the logonUsername and logonPassword fields in the form that submitted to this DataAction are passed as the two parameters that my authenticateUser method on the AppModule requires.
    I have also overriden the data action class to customise the findForward() method to route the user depending on if the method call worked or not.
    And here's the code for the customized FindForward in the DataAction:
    protected void findForward(DataActionContext actionContext) throws Exception
    HttpServletRequest request = actionContext.getHttpServletRequest();
    HttpSession session = request.getSession();
    String target = "fail";
    //Get the result of the Model Method call
    JUCtrlActionBinding method = actionContext.getCustomMethod();
    boolean successfulLogon = ((Boolean)method.getResult()).booleanValue();
    if (!successfulLogon)
    // If the logon fails we need to do the following
    // 1. Increament the counter once this exceeds 3 any logon will fail
    // 2. Create an error message to display on the logon screen
    // note this is a non specific error to prevent hackers from
    // knowing that they at least got the username right or from
    // knowing that there is a Max attempts value if they are trying
    // an automated attack
    Integer attempts = (Integer)session.getAttribute("logonAttempts");
    int intAttempts = 0;
    if (attempts != null)
    intAttempts = attempts.intValue();
    session.setAttribute("logonAttempts", new Integer(++intAttempts));
    //The error message comes out of the ApplicationResources.properties file.
    actionContext.getActionErrors().add("general",new ActionError("logon.error.logonFailed"));
    this.saveErrors(actionContext.getHttpServletRequest(),
    actionContext.getActionErrors());
    else
    //If connection was OK do we need to save the username in a cookie?
    String remember = (String)request.getParameter("logonRemember");
    int cookieLife = 0; //Expire
    if ( remember != null && remember.length()>0 )
    cookieLife = 2592000;
    String name = (String)request.getParameter("logonUsername");
    Cookie userCookie = new Cookie("CARA_USER_COOKIE",name);
    userCookie.setMaxAge(cookieLife);
    actionContext.getHttpServletResponse().addCookie(userCookie);
    target = "success";
    actionContext.setActionForward(target);
    I hope this helps anyone looking to implement something similar. It also illustrates the "preferred" way of executing a client method and working with the result.

  • Access Application Services from Web Dynpro DC

    Hi Experts,
    We created a CAF DC which has an application service called ClientAppService, with a method findClientsById. We also created another DC, a Web Dynpro DC, which makes use of the model generated by the CAF DC. We have programmatic access to the application service through
    ClientAppServiceProxy.findClientsById()
    , but when running the DC which makes this call we receive the following error:
    com.sap.caf.rt.exception.CAFBaseRuntimeException: Query with name findClientsById does not exist
    We've managed to call Application Services before, but that was when the Web Dynpro was in the same DC as the CAF services. Any ideas on how to fix this?
    Thanks,
    JP

    Hi Smith,
    One of the possible reasons of this error is may be your CAF project is not properly deployed in the Server in which you have deployed your WebDynpro project. So during the execution of the WebDynpro project while it tries to invoke this findby from the Application Service of your CAF project it fails to find a match. May be by mistake you have deployed your CAF Application Service first and added the findBy method later. So if your properly deploy your total CAF project in the same server in which you have deployed your WebDynpro project it may resolve your problem.
    Thanks and Regards
    Avijit

  • Access Application Class from Model Class in BSP

    Hello,
    I am developing a BSP Application based on MVC. Is there any way, I can access the Application Class's Attribute from a Method in the Model Class?
    Thanksin Advance.
    Regards
    Gladson

    Hello,
    I solved it by passing the application class attribute to the model method, from the controller class.
    Regards
    Gladson

  • Accessing application methods from EL

    Hi all,
    I do not consider myself a newbie but I wonder sometimes when I can't solve these problem; Tomcat can be such a bugger to configure, especially when they change the schemas on every release.
    Anyway. I have a couple custom tags in my header.jspf file. I use the <c:import> action to include it in all documents on that virtual host.
    This is how I originally achieve this task:
    <c:import url="http://home.localhost/templates/header.jspf">
         <c:param name="newsData" value="http://home.localhost/news/news_2004-06-27.xml" />
         <c:param name="menuData" value="<%= application.getRealPath("WEB-INF/home-menu.xml") %>" />
    </c:import>Now I have decided to make everything xHTML compliant i.e. I no longer want to use and can not use <% ... %> scriptlet tags any more.
    I do not know however, how to call methods such as application.getRealPath(...) from, EL for example?
    How can I accomplish this?
    I'm hoping for something like:
    <c:import url="http://home.localhost/templates/header.jspf">
         <c:param name="newsData" value="http://home.localhost/news/news_2004-06-27.xml" />
         <c:param name="menuData" value="${application.getRealPath("WEB-INF/home-menu.xml")}" />
    </c:import>I think instead of using application I have to use servletContext, but I do not know if a attribute key/value exists that represents the servlet-path.
    Any and all help appreciates.
    Kind Regards,
    Darren Bishop

    Hey evnafets,
    Thanks for your comback.
    I had actually exhaustively tried everything, including your suggestion
    ${pageContext.servletContext.realPath}I solved it in the end with the following:
    <jsp:scriptlet>
         pageContext.setAttribute("menuData", application.getRealPath("WEB-INF/home-menu.xml"));
    </jsp:scriptlet>
    <c:import url="http://home.localhost/templates/header.jspf">
         <c:param name="newsData" value="http://home.localhost/news/news_2004-06-27.xml" />
         <c:param name="menuData" value="${menuData}" />
    </c:import>I previously did not know that JSP scripting syntax had been changed to XML elements. It works fine but I do not like it at all... effectively Java code still remains in the page which I am not happy about; wanted clean XML code, I suppose with my definition of clean not beingthe above.
    I am familiar with JSTL functions, but I can be quite stubborn if it seems that the functionality should already exist; why does the application/servletContext not have an attribute REAL_PATH or something. Then you can concatenate anything you want on the end.
    Again, thanksfor reply.
    Regards,
    Darren B

  • Best Performance? - having a single stateless java pojo as delegate- give it application scope?

    I'm curious about which is best from a performance standpoint -<br /><br />All of our flex calls access a single java pojo. In my remoting-config.xml I'm currently declaring the destination a property scope of 'application': <br /><br /><destination id="UIServicesDelegate"><br />    <channels><br />      <channel ref="my-amf"/><br />      <channel ref="my-local-amf"/ <br />    </channels> <br />     <properties><br />        <factory>spring</factory><br />        <source>uiServicesDelegateBean</source><br />        <scope>application</scope><br />    </properties><br /></destination><br /><br />All of the UIServiceDelegate methods are stateless however, so I'm wondering if I'm gaining anything by giving it scope session. Since their all stateless I"m assuming application scope would be the best from a performance standpoint? I'm assuming in this case only one object will ever be instantiated? <br /><br />Assuming it was between Session and Request scope, is there a lot of overhead instantiating the new server side object each time? I would assume performance would be better using the Session in this case, with the only draw back of some server-side ram being chewed up storing the object in the Session. <br /><br />If you want "singleton" type approach, I figure just using application scope is the preferred approach?

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

  • Accessing 2 DDLs from an App

    Hi,
    I am accessing 2 DLLs from my app.
    In one DLL i am defining an interface to make a DBConnection using
    getConnection method and the other DLL has the interface
    UpdateDB() which updates the database.
    My app uses these two dlls to perform DBConnection first followed
    by UpdateDB.
    I like to know if this works, if so can some one point me to a location
    where i can find something like this.
    Please help.
    Regards
    Venkat

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

  • Set and access application items

    Hi,
    How can I set and access the values of application items from package? is't recommended to access application items from procedure?
    thanks,

    Hi,
    in PL/SQL functions or procedures regardless if they are packaged or not:
    set procedure: APEX_UTIL.SET_SESSION_STATE('MY_ITEM','myvalue');
    get function: V('MY_ITEM')
    Regards Garry

  • Accessing env-entry from out side bean

    Hi,
              I have my env-entry element declared in ejb-jar.xml like this
              <env-entry>
              <env-entry-name>ConfigFile</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>centaur</env-entry-value>
              </env-entry>
              and if I access that value from the EJB(MDB) of that ejb-jar.xml, it is giving the right value. But when I am trying to retrieve the same from a java class, that is throwing exception "javax.naming.NameNotFoundException: Unable to resolve 'ConfigFile' Resolved ; remaining name 'ConfigFile'"
              I think this is because env-entry has access to only EJB or MDB to maintain security?
              or can env-entry elemenets cab be accessed outside the EJB and some thing I am doing wrong here?
              can some one help me here?

    The java:comp/env namespace is local to the J2EE component (ie the EJB).
              You could certainly have a business method that returned the value and call the business method from a java class.
              Or your EJB could lookup the env-entry in JNDI and store it in another data structure.
              -- Rob
              WLS Blog http://dev2dev.bea.com/blog/rwoollen/

Maybe you are looking for

  • Ipad fail on road in Shanghai. iTunes screen of death

    I have been traveling with the ipad in China for over a week now and it's been working beautifully. Today I turned it on and it shows an iTunes iconand cable and is lOcked up. Can't get it to do anything. Reboot etc does not work. I'm depending on th

  • Dir 5.1 on Solaris 8 simply crashes

    Our 5.1 DS crashed twice this day without putting any information in the access and error logfiles. Also /var/adm/messages showed nothing. When I run /distr/idir/5.1/bin/slapd/server/idsktune I get the following output below. =======output idstune===

  • Problem selecting linked images in CS5

    Just changed to InDesign CS5 and find, on working on a document created in CS4, I can't select images (which were links created inPhotoshop). The only things I can select are objects that I had created in InDesign itself. Why?

  • FM to return SC details - importing Approver ID

    Experts, I notice that FM  BBP_BW_APPROVER_COUNT gives the approver's for the SC. Is there any FM that i could give the approver and it returns the SC that he has to approve ?? Thanks in advance, Mário.

  • Problem in SAP Script Printing

    Hi All, We are having a very strange problem while passing the data in SAP Script.Actually we are doing the Script of Payment Advice(FI/CO),but while calling the Function Module 'RSPO_RID_SPOOLREQ_LIST' in the driver program the values are lost.I hav