schedulerclient.java

来自「一个java工作流引擎」· Java 代码 · 共 59 行

JAVA
59
字号
package org.jbpm.scheduler;

import java.io.*;
import java.net.*;

/**
 * is the external client that will provide a request-thread to the 
 * {@link SchedulerServer}.
 * 
 * The scheduler client will do this by sending a http request to the 
 * scheduler servlet.  The default url is http://localhost:8080/jbpm.scheduler/schedulerservlet
 * To start the SchedulerClient type the following in a command line prompt : 
 * <pre>
 *   java -cp jbpm.core.jar org.jbpm.scheduler.SchedulerClient
 * </pre>
 * If you have configured the SchedulerServlet on a different address, 
 * just provide an altenative url as the single parameter to the application.
 * E.g.
 * <pre>
 *   java -cp jbpm.core.jar org.jbpm.scheduler.SchedulerClient http://localhost:8080/myschedulerservleturl
 * </pre>
 */
public class SchedulerClient {

	public static void main(String[] args) {
    String urlText = "http://localhost:8080/jbpm.scheduler/schedulerservlet";
    
    if ( ( args != null )
         && ( args.length > 0 ) ) {
      urlText = args[0];
    }
    
    
    while(true) {
      long millisToWait = 5000;
      try {
        System.out.println( "triggering the server to execute jobs" );
				URL url = new URL( urlText );
				InputStream inputStream = url.openStream();
				byte[] buffer = new byte[16];
				int bytesRead = inputStream.read( buffer );
				String result = new String( buffer, 0, bytesRead );
				System.out.println( "waiting for " + result + " milliseconds" );
				millisToWait = Long.parseLong( result );
			} catch (Exception e) {
				e.printStackTrace();
			}
      // we use 2 separate try-catch blocks because we want to 
      // sleep for a period, even if something goes wrong with 
      // the client-server communication.
      try {
				Thread.sleep( millisToWait );
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
    }
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?