Sharing application scope

This question has been asked in the past but not answered completely, so here is my issue:
I am currently working on a site that has two separate sections(one public section and another admin section), but need to share the same Application variables.
Basic file structure....
Root
-- Admin  -- Application.cfc  -- index.cfm 
-- Application.cfc  -- index.cfm  
The public side will contain the application start and end code and the the admin Application.cfc will include the public application.cfc(<cfinclude template="../Application.cfc" />) and the login logic.   The reason I am trying to do this is that my application scope needs to be accessible by both sides. My understanding is that the CF server will treat this all as one application since they have the same name.
During my testing, I set application.cfcroot variable in the public application.cfc.  That variable is not accessible in the admin subfolder.  My understanding is the fact that by including the original(public) application.cfc, the application.cfcroot variable will be accessible in subfolders(in this case: admin).  Th error I get is that the variable is undefined.  I test this by trying to dump the application right after I include it in my application.cfc located in the admin folder.  For example:
Contents of application.cfc in root:
<cfset this.name="myapp" >
<cffunction name = "onApplicationStart">
     <cfset application.cfcroot = "myapp.cfcs.">
</cffunction>
Contents of application.cfc in admin folder:
<cfinclude template="../Application.cfc" />
<cfdump var="#application#" label="1" />
error:
Variable APPLICATION is undefined.
Any ideas?

Session management is enabled as the rest of my app relies on sessions.  Also, application variables are enabled in the administrator.  I had no idea it was in there, but it is checked.  Here are my Application.cfc files:
Application.cfc (root/gemstartech directory)
<cfcomponent>
          <cfset this.name="gemstartech" >
          <cfset this.sessionmanagement=true >
          <cfset this.setclientcookies=true >
          <cfset this.setdomaincookies=false >
          <!---This sets timeout to be 20 minutes(days, hours, minutes, seconds)--->
          <cfset this.sessiontimeout="#CreateTimeSpan(0,0,20,0)#" >
          <cffunction name = "onApplicationStart">
        <cfset application.cfcroot = "gemstartech.cfcs.">
          </cffunction>
          <cffunction name = "onRequestStart">
                    <cfparam name="CGI.REMOTE_ADDR" default="">
                    <cfinclude template="shared/udf.cfm">
          </cffunction>
</cfcomponent>
Application.cfc (root/gemstartech/admin directory)
<cfcomponent extends="gemstartech.Application">
<cfset this.applicationTimeout = "#createTimespan(1,0,0,0)#">
<cfset this.sessionManagement = "true">
<cfset this.sessionTimeout = "#createTimeSpan(0,0,20,0)#">
<cffunction name = "onApplicationStart">
     <!--- The keyword super stands for the parent Application component. Calling its onApplicationStart method will initialize the variable application.cfcroot --->
     <cfset super.onApplicationStart()>
     <cfset application.testAdminVar= "aValue">
</cffunction>
<cfdump var="#application#" label="1" />
<!--- log user out if they click 'logout' --->
<cfif isDefined("url.logout") >
          <cfset structClear(session)>
          <cflogout>
          <cflocation url="index.cfm" addtoken="no">
</cfif>
</cfcomponent>

Similar Messages

  • Application scope variables ... an easier way or not ?

    Instead of sharing application scope variables through the
              servletContext()/application I am using a normal singleton class (or maybe
              static class) to share all my application varaiable. It works fine and it
              takes a lot less code to write.
              It seamed logical to do this a static classes or singletons are shared
              within a single servletContext/application (which there seems to be only one
              per WL instance anyway). (singleton is quite nice pattern coz. all
              jsp:useBeans with the application scope are by definition singletons)
              Has anoyne tried something similar or maybe know of the problem with this
              approach. I assume that server will never reinitialise application level
              variables ...... hope the assumption is correct. ....
              

    When you specify application scope, the JSP stores/retrieves the value
              into/from the servlet context. You may already know this, but it sounded
              like what you thought you were somehow avoiding.
              Cameron Purdy
              http://www.tangosol.com
              "Bohinc D" <[email protected]> wrote in message
              news:[email protected]..
              > Instead of sharing application scope variables through the
              > servletContext()/application I am using a normal singleton class (or maybe
              > static class) to share all my application varaiable. It works fine and it
              > takes a lot less code to write.
              >
              > It seamed logical to do this a static classes or singletons are shared
              > within a single servletContext/application (which there seems to be only
              one
              > per WL instance anyway). (singleton is quite nice pattern coz. all
              > jsp:useBeans with the application scope are by definition singletons)
              >
              > Has anoyne tried something similar or maybe know of the problem with this
              > approach. I assume that server will never reinitialise application level
              > variables ...... hope the assumption is correct. ....
              >
              >
              >
              

  • Will the Application Scope be shared across the cluster in a multi-node OC4

    Hi,
    I have the following requirement:
    Users of the application can only have single (browser) session. When a user who already has a session connects again, he should no longer be allowed to access the older session.
    My proposed implementation is:
    -     After successful login – possibly using a Session Listener - an entry is made in a HashMap UserSessions that lives in the application scope. Key is the username, value is the session id (HttpSession.getId()).
    -     For every request, using a ServletFilter, we check whether the session is still in the UserSessions HashMap for the current user. If a new session has been created for the same user, the session id for that new session is in the UserSessions map and the servletfilter will not find the session. In that case, the filter should invalidate the session and forward to the user to an error page.
    However, the application will run on a multi-node OC4J cluster. I am starting to wonder:
    Will the Application Scope be shared across the cluster in a multi-node OC4J environment?
    I know session state can be shared. But what application state/scope?
    Does anyone know? Do I have to do anything special in the cluster or the application to get this to work?
    Thanks for your help.
    Lucas

    gday Lucas --
    Application scope is not replicated across JVM boundaries with OC4J.
    I'm sure this used to be described in the doc, but I can't find it now from a quick scan.
    If you wanted to use this type of pattern, you could look to use a Coherence cache as distribution mechanism to share objects across multiple JVMs/nodes.
    -steve-

  • Locking when using a component as an object in the application scope...

    I have a component that I am building right now that hold
    application settings that are stored in a database table. The
    settings are maintained in a structure "variables.settings" within
    the component and can only be accessed by get and set methods. I
    use the following to create the instance of the object:
    <cfset application.settings =
    createObject("settings","component").init() />
    Now when getting a setting I do not think locking is needed
    as its just reading the value and I am not really concerned with a
    race condition...
    But when using the set method which will update the value of
    the setting.... should I be locking that as technically the object
    is in a shared variable scope? Or is it safe because its within the
    cfc/object?
    If locking is needed, would I need to lock when using the set
    method? or can I just build the lock into the set method so that
    its always there?

    To disagree with craigkaminsky, I think you only need to lock
    if you are
    concerned about race conditions and what could happen during
    a 'dirty
    read' and|or conflicting writes.
    A lot of developers have an old impression of ColdFusion that
    one *must*
    lock all shared scope variable access to maintain a stable
    application.
    This dates from the ColdFusion 4.5 days where there where
    bugs in
    ColdFusion that could cause memory leaks and eventual
    application
    instability if one did not lock shared scope reads and
    writes. This has
    long been fixed, but the advice persists.
    So now it is only a matter of your data and what would happen
    if one
    user read an old value while it was in the process of being
    updated by
    another user. Or could two users be updating the same value
    at the same
    time and cause conflict. If either of those two statements
    are true,
    then yes you should use locking as required by your
    application.
    But if they are both false and it does not matter that user A
    might get
    the old value microseconds before user B changes it. Or there
    is no
    concern with user A changing it once and user B changing it
    again to
    something different moments later without knowing the user A
    has already
    changed it. Then locking is probably unnecessary.
    There can be a cost to over locking shared variable writes
    and|or reads.
    Every time one creates a lock, one is single threading some
    portion of
    ones code. Depending on how the locking is done, this single
    threading
    may only apply to individual users or it may apply to every
    single user
    on the entire server. Either way, too much of this in the
    wrong places
    can create a significant bottle necks in ones application if
    too many
    user requests start piling up waiting for their turn through
    the locked
    block of code.

  • What are the pros and cons of storing heavely used CFCs in the application scope?

    I've been storing all the required CFCs for a site in the application scope. During onApplicationStart I do something like this application.objSomeCfc =CreateObject('component', 'com.someCfc').init().
    Here is my reasoning.
    Get the CFCs initialized once and stored in memory for better performance.
    Using CreateObject several times on each page load can have a negative impact on performance.
    Having one place to create application scoped CFCs makes it easier to manage code.
    So is my thinking flawed? Are there any additional pros or cons for dealing with CFCs? Is there any docs, articles, blogs, videos, frameworks, ...... that I should check that may change my perspective on how I'm doing this?
    Thanks

    Your approach is fine, depending on how many and what type of CFCs you are talking about. If they are "singletons" - that is, only one instance of each CFC is needed to be in memory and can be reused/shared from multiple parts of your application - caching them in the application scope is common.  Just make sure they are thread safe ("var" or local.* all your method variables).
    You might consider taking advantage of a dependency injection framework, such as DI/1 (part of the FW/1 MVC framework), ColdSpring, or WireBox (a module of the ColdBox platform that can be used independently).  They have mechanisms for handling and caching singletons.  Then you wouldn't have to go to the application scope to get your CFC instances.
    -Carl V.

  • Looking for best practice on application scope beans

    Hey – a portal newbie here. I’ve got some application scope beans that need to be initialized on startup. First thought was to create a servlet that would set the bean. Then I saw the GlobalApp setting, but I think that looks like it is more session scope than application… Looking to be corrected here if I am wrong.
    Is there a place where these type of things traditionally happen? Read only, so no cluster worries (I think) Using WLP 8.1 SP4 and looking for best practices. Thanks for the help!

    To support "code sharing" you need an integrated source code control system. Several options are out there but CVS (https://www.cvshome.org/) is a nice choice, and it's completely free and it runs on Windows, Linux, and most UNIX variants.
    Your next decision is on IDE and application server. These are usually from a single "source". For instance, you can choose Oracle's JDeveloper and Deploy to Oracle Application Server; or go with free NetBeans IDE and Jakarta Tomcat; or IBM's WebSphere and their application server. Selection of IDE and AppServer will likely result in heated debates.

  • 300 requests per hour reading from Application scope Good/Bad idea

    I am saving some html in application scope & reading with
    <cflock readonly.
    Will it be a problem if more than 5 requests are made per
    second?
    Does deadlocks occurs with readonly-cflock?
    Thanks

    While creating/changing application scope variables in a
    lock, I think there must be an exclusive lock. You must be careful
    not to set any shared variable such as application inside a read
    only cflock tag.
    I also would suggest to check the usage of Application.cfc
    and onApplicationStart method. You can set application default
    variables and constants in onApplicationStart method in your
    Application.cfc.

  • JWS Lifecycle/Scope (Axis "Application Scope" Behavior in WebLogic?)

    Apache Axis supports three different scopes for web services (Application, Request, Session). The documentation for Application scope says the following:
    <p>
    <i>"Application scope means there will only be a single instance of the service class for the entire AxisEngine. This means that that you, the developer of the service class must make sure all your methods are thread safe. ... Any state you keep in your service object will be shared across all invocations for the lifetime of the engine."</i>
    <p>
    How can I achieve the same behavior with a JWS service developed under WebLogic. ...a singleton web service accessed by multiple clients that maintains a shared state for the lifetime of the WebLogic server.
    <p>
    Thanks in advance,<br>
    Troy

    Apache Axis supports three different scopes for web services (Application, Request, Session). The documentation for Application scope says the following:
    <p>
    <i>"Application scope means there will only be a single instance of the service class for the entire AxisEngine. This means that that you, the developer of the service class must make sure all your methods are thread safe. ... Any state you keep in your service object will be shared across all invocations for the lifetime of the engine."</i>
    <p>
    How can I achieve the same behavior with a JWS service developed under WebLogic. ...a singleton web service accessed by multiple clients that maintains a shared state for the lifetime of the WebLogic server.
    <p>
    Thanks in advance,<br>
    Troy

  • Component in Application Scope and cflock

    Hi,
    I have an CFC that I set in application scope in the
    onApplicationStart method which contains some system parameters,
    one of which is a flag saying whether the site is currently
    "Online". I call a method on this CFC in the Application.cfc
    "onRequest" method to see if the flag value has changed.
    This method looks up a parameter set in the database that
    says whether the site is "online" or "offline". If the site is
    currently online, I want to only redo the query every 5 mins.
    However if the site is offline, I want to check more frequently
    (every 5 secs) as to whether the flag has changed back.
    What I am not sure of, is whether I need to be using
    <cflock> when I change from "online" to "offline"? There is
    only a single instance of this object, but what happens if multiple
    requests are calling the "isSiteOnline" method simultaneously? Is
    this "safe"?
    Some code snippets are attached to illustrate.
    Any advice would be greatly appreciated.
    Regards,
    Andrew.

    > <!--- DO I NEED TO USE CFLOCK HERE???? --->
    No, in either situation.
    Ask yourself... what would the ramifications be of two
    requests hitting
    that line of code "simultaneously"? The end result is that
    both of them
    are setting the variable to the same static value... so
    that's what's going
    to end up happening: variables.instance.cacheInterval is
    going to be set to
    300 (or 5) in each situation.
    You could well with to lock a block of code which - if called
    simultaneously via more than one request - could act on
    shared storage
    space (server, application or session data) differently and
    incorrectly
    than is intended.
    eg:
    <!--- application bootstrap process --->
    <cfif not structKeyExists(application, isInitialised and
    not
    application.isInitialised>
    <!--- initialisation process, whatever it is --->
    <cfif allOK>
    <cfset application.isInitialised = true>
    <cfelse>
    <cfset application.isInitialised = false>
    </cfif>
    </cfif>
    So a sequence of events could be (say the user is hitting the
    site with two
    different browsers):
    REQUEST1: application.isInitialised doesn't exist
    REQUEST1: starts the init process
    REQUEST2: application.isInitialised STILL doesn't exist
    REQUEST2: starts the init process *again*
    REQUEST1: sets the application.isInitialised value
    REQUEST2: sets the application.isInitialised value
    Obviously one does not want two request running the
    initialisation code.
    note this is a slightly contrived example, as if one has an
    OnApplicationStart() method, then it will only run once, and
    that's where
    one would have the init code, but it demonstrates the issue.
    Google "race condition". Those are the situations in which
    one needs to
    lock blocks of code.
    Adam

  • 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

  • Is Weblogic Cluster  supports Application scope Objects?

              Our Application is mainly depends on Application scope objects. On one m/c, it
              is perfect.
              Now, we want to support the failover , load balancing ... (High Availability).
              I know, weblogic cluster supports HttpSessions, EjbObjects ... etc. What about
              Application scope objects.
              we are planning for weblogic server which supports the our requirements.
              If not, what is the solution to make it work by using Weblogic server.
              for eg: I can give what type of application we are developing --- similar to
              textchat.
              our application is real time application.
              

    Even a singleton is not good enough as singletons are good only in the VM they were
              created it. One way is to have a distributed object such as a stateful session bean of
              which only one instance exists. U can create it at startup and store its handle in
              some persistent storage as well as a singleton. This ensures that even if the
              singleton doesnt contain it the refgerence to it can be obtained.
              There will be some problems with this setup as people should not allow it to create
              instances of it . Any such endeavor will lead to a CacheFullException.
              But essentially that seems possible.
              Even the 2.3 Servlet specification mandates that ServletContext and Application level
              object is only valid inside the JVM which created it. HttpSessions are replicated
              SessionContexts are not and are not likely to be in any J2EE application server
              Sameer
              Devi wrote:
              > One more comment from my side,
              > U mentioned "EXCEPT FOR JNDI" , if this is possible, how can we acheive?
              > Can U give brief description ? Take textchat example itself? since, our application
              > is almost have same mechanism. If it is < 1 sec delay means acceptable for this
              > release.
              >
              > Thanks,
              > Devi
              >
              > "Cameron Purdy" <[email protected]> wrote:
              > >Weblogic doesn't support replicated / synchronized app scope objects
              > >across
              > >a cluster except for JNDI, which is probably not a good solution for
              > >what
              > >you are describing.
              > >
              > >If you need a real-time shared fault-tolerant fail-overable high-performance
              > >load-balanced high-scale data store, then let me know when you find one
              > >;-)
              > >.... seriously, there are not a whole lot of good general purpose solutions
              > >in this space. There are some things to look at but they are all expensive:
              > >
              > >Persistent PowerTier on top of Oracle - a caching entity EJB server
              > >Jasmine (or whatever it is called this week) - an object oriented
              > >distributed data store
              > >....
              > >
              > >Peace,
              > >
              > >--
              > >Cameron Purdy
              > >Tangosol Inc.
              > ><< Tangosol Server: How Weblogic applications are customized >>
              > ><< Download now from http://www.tangosol.com/download.jsp >>
              > >
              > >
              > >"Devi" <[email protected]> wrote in message
              > >news:[email protected]...
              > >>
              > >> Our Application is mainly depends on Application scope objects. On
              > >one
              > >m/c, it
              > >> is perfect.
              > >> Now, we want to support the failover , load balancing ... (High
              > >Availability).
              > >>
              > >> I know, weblogic cluster supports HttpSessions, EjbObjects ... etc.
              > > What
              > >about
              > >> Application scope objects.
              > >> we are planning for weblogic server which supports the our requirements.
              > >>
              > >> If not, what is the solution to make it work by using Weblogic server.
              > >> for eg: I can give what type of application we are developing ---
              > >similar to
              > >> textchat.
              > >> our application is real time application.
              > >>
              > >
              > >
              

  • Using Application Scope Javabean to hold data?

    I have a set of (4000) records I would like to store in a Javabean to be used within mutiple JSPs. I am using JSP and Javabeans, no EJBs. My question is should I use Application scope for the Javabean to be shared for all the JSPs instead of a Sesstion scope to limit stress to the server? Thanks.

    I think use session scope. Application scope may tie up resources u might not need. That is my personal opinio though.

  • Why can I not see shared applications on iTunes on a Mac but can on Itunes under Windows

    Hello
    1. I have a Mac Laptop, a Windows 7 laptop and an IPAD Air. I have an application on the IPad that shares files.
    2. On both the Windows and Mac machines, I have the latest versions of ITunes installed.
    3. With Image and IPhoto, I can browse the Documents directory of the shared application on the IPAD.
    4. On the Windows Machine, on ITunes, under the Apps section, at the bottom of the screen, I can see the shared application and the shared Documents directory.
    5. On my Mac Machine, on Itunes, under the Apps section, at the bottom of the screen, I can NOT see the same shared application on the IPAD that I see on the Windows machine.
    6. In the upper right corner of Itunes on the MAC it does show "1 App" but I see no way to click on the app under ITunes and to browse the shared directory on the IPad
    Any thoughts on what I have to do to make the Shared App show up on the Mac that shows up on the Windows machine in ITunes?

    Did you put your audiobooks on your computer?
    They will only be where you put them.  You need to copy them from your old computer or your backup copy of your old computer.

  • Calling a method for application scope

    I have a method that initializes a hashtable.
    That method should be called once when my web app starts, I need to load that hashtable into memory so whenever a user needs a value from that hashtable, it readily access the hashtable and doesn't load it everytime it is called. How do I do that?

    Just put it in the application scope in the faces-config.xml?

  • View Objects in the shared application module is not refreshing

    Hi ,
    I have view objects defined shared apps module. This view objects are used for creating lovs which won't change very frequently. I have set the AutoRefresh=true for this view objects. I do have a UI to update the underline table for these lovs. The view objects defined in the shared application module is not getting reflected even I add a new value in the database. Is there any way to refresh these lovs as soon as its added to db?
    Thanks
    Suneesh

    I will explain my scenario ;
    I have a view object(ViewA) where I have defined many LOVs for different attributes. Thes LOVs are using the shared application module's view object (shared_view1,shared_view2...etc) as List DataSource. Where exactly I need to set the auto refresh property=true. Currently I have set all of my shared apps view objects's(shared_view1,shared_view2...etc) autorefresh property=true.Do I need to use the autorefresh =true in the ViewA ?
    What is the concept of autorefresh=true ? Wiill it refresh automatically the view object nexttime i am accessing the page after the db inserts ? Is there any time delay there ? if there is it something configurable ?
    Thanks
    Suneesh

Maybe you are looking for

  • Adobe Bridge Gallery Not Loading in .pdfs

    Recently I created a flash gallery with adobe bridge that I intend to embed into a pdf that will be available as a download via my company's website. I've attached the required resources directory as well as the appropriate flahvars required to displ

  • Media Center Deluxe III no fullscreen

    The software refuses to go fullscreen when in the screens: Video Clips or Recorded TV (which are basicaly the same) The little fullscreen button is disabled (for both mouse or remote) The home and back button (top left) are also disabled and I'm lock

  • Phototsmart 5510 ePrint server connection error

    Hi, I have a Photosmart 5510 with Windows 7.  I am trying to turn on the ePrint service, but it has to run an update before it will enable.  However, every time I try to enable it it gives me a "Server Connection Error" after trying to connect to the

  • Printing format problem from Linux GUI

    Hi! We have configured Printer for Linux Clients with "U" access method and users are able to take print out through Linux GUI.  However, the printout is not in desired format.  For example, PO printout has rows, columns, lines, borders, etc. which a

  • Watching rented movies

    When i watch movies that i have bought from i tunes rental the aspect ration is not correct. I lose half the screen (top and bottom) i have tried ammending the seting in the view drop down however this makes the problem worse