Concept : Understanding the Main Class and Run Functions
Contents |
[edit] DEPRECATED
[edit] Description
To ensure that your applications's start-up code runs as intended, Bungee Connect provides you with the ability to add a Main class and Run functions or assign an existing class and functions to take on those roles within your application's primary AppProject. Then, when your application starts, an instance of the Main class is created, and the run function is executed. The run function provides a location to place your application's start-up code and to initialize items when your application runs.
[edit] Main Class and Run Functions
When you add a main class to your AppProject, there are two functions that are added with the class:
- run—called before any response is sent to the browser
- afterRenderInitialization—called immediately after the initial page renders and before the user can do anything to interact with your application
[edit] Optimizing Your Application Start Time
If you have an application that loads slower than you want, you can optimize apparent application load times by splitting the application load and initialization functionality between the two functions on your application's main class.
[edit] Understanding the run Function
When a request comes in to start up an application, if you have added a Main class or assigned a class to act as the application's "Main" class, that class is checked to see if there is a function which uses the MainFunction function interface.
Note The run function added with your main class uses this interface by default. If you assign a class to act as a main class, you must also assign the MainFunction function interface (using the Interface List property) to a function within that class.
The run function is called before any response is sent to the browser and executes in its entirety before any user interface element gets displayed within the browser. This means that any functionality you place in this function has a direct impact on how long it takes for a user to see something appear in the application area of the browser. Keep this function as small and tight as possible so your application launches quickly. The main purpose for providing a function to which you have assigned the MainFunction function interface, is to control what your users see first. You may want to use the run function to set the state of single sign on features, or to access a database etc., in order to properly populate your interface.
[edit] Using the run Function for an Application Process
One of the options available to you when you add an AppProject to a solution is to make that AppProject a No GUI (Process Only) project.
Note If you are choosing this option, it may make sense for you to also choose Main Class from the Template drop down list. Doing so adds a main class and run functions to your solution, saving you the trouble of adding these separately.
Choosing the No GUI (Process Only) option allows you to create a non-GUI process or "application." While you can create sophisticated Model structures and workflows for your application, all the functionality you create for such an application must be called within the context of your AppProject's run function. When the run function terminates, so does your GUI-less application. You deploy your non-GUI applicaiton just as you would any other application, so the application is accessible by URL.
You might find this type of application useful in a scenario where a server encounters an error. In this circumstance, you may want the error condition to trigger a process to send email alerts using SMTP. Your GUI-less application could provide the machinery for sending the email alerts, with the URL of your deployed non-GUI application acting as an argument for the error handling function.
[edit] Understanding the afterRenderInitialization Function
Once the "run" function returns, the browser renders the first page. Immediately after the initial page renders (and before the user can do anything to interact with your application), the afterRenderInitialization function added with your Main class is called.
Note If you assigned an existing class to act as your main class, you must also assign the MainPostRenderInit function interface (using the Interface List property) to a function within that class so that function can act as the afterRenderInitialization function.
You should use this function to do most of your application initialization. For example, if your application requires user authentication, this function is a good place to call your login dialog. This allows any needed initialization to occur in a way that seems natural to your end users.
[edit] Run Functions Diagram
See the image below for a graphical explanation of what happens when you launch an application under the conditions described above.

[edit] See Also
Providing a Main Class And Run Functions
Solutions and Projects
Creating a Solution
Adding a Project to a Solution



