Created
March 6, 2016 07:17
-
-
Save jasonbronson/159bd77bbabe5af59642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package worker; | |
import java.io.IOException; | |
import org.gearman.Gearman; | |
import org.gearman.GearmanFunction; | |
import org.gearman.GearmanServer; | |
import org.gearman.GearmanWorker; | |
import org.gearman.impl.GearmanImpl; | |
public class WorkerClient { | |
private GearmanWorker gearmanWorker; | |
private Gearman gearman; | |
private GearmanImpl gearmanImpl; | |
public WorkerClient(String host, int port, String functionName, GearmanFunction function) throws IOException { | |
if (host==null || functionName==null || function==null) | |
throw new IllegalArgumentException("parameter is null"); | |
// Create a GearmanWorker | |
//gearmanImpl = new GearmanImpl(); | |
gearman = GearmanImpl.createGearman(); | |
gearmanWorker = gearman.createGearmanWorker(); | |
//gearmanWorker = gearmanImpl.createGearmanWorker(); | |
//add remote gearman server | |
GearmanServer gearmanServer = gearman.createGearmanServer(host, port); | |
gearmanWorker.addServer(gearmanServer); | |
// Register function to start working on gearman calls | |
gearmanWorker.addFunction(functionName, function); | |
} | |
public void shutdown() { | |
this.gearman.shutdown(); | |
} | |
public String testPayload(String payload) { | |
System.out.println("run payload now"); | |
return "payload returned"; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment