Backendless Support

CodeRunner - Custom Business Logic Utility

After a developer masters the topic of using a Custom Business Logic Code Generator to create Backendless timer code (review the appropriate topic to refresh the issue), it seems reasonably to download the project files with the source code.

To accomplish the successful downloading click the Download button: 


The downloaded file is a ZIP archive of the project. The contents of the archive would have the same structure as shown below:

There is a project file for IntelliJ IDEA, however if a developer uses Eclipse, it is very easy to import the project in it as well. Open the project and it would be possible to compile it without any changes. 

The code straight out of the code generator does not have any custom business logic -  it is a wrapper required by the Backendless framework. 

To add custom business logic open the timer class, it will be in the hierarchy of the /src directory. In the example below there has been added a custom code which stores an object in Backendless Data Store every time the timer runs

package com.backendless.orderprocessing.timers;
import com.backendless.Backendless;
import com.backendless.messaging.BodyParts;
import com.backendless.orderprocessing.models.Person;
import com.backendless.servercode.annotation.BackendlessTimer;
* ReminderTimer is a timer.
* It is executed according to the schedule defined in Backendless Console. The
* class becomes a timer by extending the TimerExtender class. The information
* about the timer, its name, schedule, expiration date/time is configured in
* the special annotation - BackendlessTimer. The annotation contains a JSON
* object which describes all properties of the timer.
public class ReminderTimer extends com.backendless.servercode.extension.TimerExtender
 public void execute( String appVersionId ) throws Exception
 System.out.println( "Running custom code" );
 long counter = Backendless.Counters.getAndIncrement( "age" );
 Person person = new Person(); = "Spiderman-" + counter;
 person.age = 30; person );
 catch( Throwable t )

Now that a developer has a Backendless Timer with custom code in it, the question is how to run it. Obviously the code can be deployed to the Backendless cloud, however, wouldn't it be nice to be able to run it locally first for testing and debugging purposes? 

The answer is 'YES'! This is exactly what Backendless CodeRunner for Java does. The best part is CodeRunner is already included into the ZIP file generated by Backendless Console (the file downloaded at the beginning of the article).

If a developer uses IntelliJ IDEA, the project is automatically configured to compile the code into the /classes directory shown in the screenshot above. The directory is special - this is where CodeRunner looks for custom code classes.

To run CodeRunner, open a command prompt window and change the current directory to /bin (see it in the screenshot above). Run CodeRunner using the scripts in the /bin directory. For example, on a Linux system, run the following:


The following output will appear:

Listening for transport dt_socket at address: 5005

[INFO] CodeRunner(tm) Backendless Debugging Utility
[INFO] Copyright(C) 2015 Backendless Corp. All rights reserved. 
[INFO] Version: 1.13 Build date: 20150320-1727
[INFO] Registering runner on: <a href="<a href=" https:="""=""></a>"><a href="">https://api.backendle...">">https://api.backendle...</a> with secretKey: XXXXXX-XXXXXX-XXXXXX
[INFO] Runner successfully registered
[INFO] Parsing event model...
[INFO] Build successfully: EventModel{timers=1, eventHandlers=0}
[INFO] Deploying model to server, and starting debug...
[INFO] Model successfully deployed...
[INFO] Waiting for events...

CodeRunner automatically inspects the compiled code, determines that is has one timer and registers it with the Backendless 'mothership'.

Review related topic:

Is article helpful?