We've finally reached the time when we can run both the client and server and test the RMI configuration. The first thing to do is to start the Quartz RMI server. You shouldn't have to do anything special other than make sure the typical Quartz JARs and the server.properties file are included on the classpath. No additional JARs are necessary for RMI, but you need the ones that are required for any Quartz application.
Running the Quartz RMI Server
To run the Quartz RMI server, just run the QuartzRMIServer class as you would any other Java class. As we mentioned earlier, be sure to include all the required JARs in the classpath, as well as the server.properties file. The easiest way to accomplish this is to create a batch file (or shell script) with all of this in it. Listing 9.4 shows a sample batch file that you can use to start the server.
Listing 9.4. A Sample startserver.bat File Used to Start the Quartz RMI Server
You will need to include the necessary jars in the classpath for the command in Listing 9.4 to work correctly. These include quartz.jar, commons-logging.jar, commons-logging-api.jar, commons-collections3.1.jar, beanutils.jar, commons-beanutils-bean-collectons.jar, commons-beanutils-core.jar.
Running the Quartz RMI Client
When the server is running, you can then run the RMI client. The client can be run in the same way as the server, by creating a batch file or shell script. When you start the client, if all goes well, you should not only see the output from the client console that a remote job has been scheduled, but you should also see a message printed in the server console that it received the remote job to schedule and run.
Whereas the RMI client is designed to schedule its job and exit, the Quartz RMI server is designed to continue to run until you type exit. The server should write that it received a remote job to schedule and then go about its business of waiting for more clients to connect. This means that you can run the client multiple times, and this is exactly what you would want from a design like this.
You can just type exit when you're finished running the examples.
What's Up Next?
This chapter introduced a new way to interact with the Quartz Scheduler that wasn't possible before. Using Quartz with RMI enables you to build applications for which you can separate the components and distribute them across multiple machines. This is a powerful concept because it offers better scalability without additional development work.
The next chapter takes this concept to the next level by showing how it's possible to use Quartz within a J2EE application server. Interestingly, Java application servers all use a form of RMI as well to support remote method invocation.
Scheduling in the Enterprise
Getting Started with Quartz
Cron Triggers and More
JobStores and Persistence
Implementing Quartz Listeners
Using Quartz Plug-Ins
Using Quartz Remotely
Using Quartz with J2EE
Quartz and Web Applications
Using Quartz with Workflow
Appendix A. Quartz Configuration Reference