Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Gearman Worker Example Issues
Post Body

I'm using the Gearman off of github. I can't seem to find out how to build a Gearman example worker I keep running into issues with NPE. I've tried many methods and searched for documentation on what the proper steps are to no avail. Any help would be greatly appreciated.

Exception in thread "main" java.lang.ExceptionInInitializerError at org.gearman.Gearman.createGearman(Gearman.java:53) at worker.WorkerClient.<init>(WorkerClient.java:33) at worker.Main.main(Main.java:32) Caused by: java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434) at java.util.Properties.load0(Properties.java:353) at java.util.Properties.load(Properties.java:341) at org.gearman.context.GearmanContext.loadProperties(GearmanContext.java:175) at org.gearman.context.GearmanContext.loadProperties(GearmanContext.java:158) at org.gearman.context.GearmanContext.loadProperties(GearmanContext.java:143) at org.gearman.context.GearmanContext.initProperties(GearmanContext.java:74) at org.gearman.context.GearmanContext.<clinit>(GearmanContext.java:66) ... 3 more

` 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";
}

}

package crawler_worker;

import java.io.IOException;

import org.gearman.; import org.gearman.impl.;

import crawler_worker.WorkerClient;

public class Main {

public static void main(String[] args) {

    if (args.length == 0 || args.length > 3) {
        usage();
        return;
    }
    String host = Constants.GEARMAN_DEFAULT_TCP_HOST;
    int port = Constants.GEARMAN_DEFAULT_TCP_PORT;
    String payload = args[args.length - 1];
    for (String arg : args) {
        if (arg.startsWith("-h")) {
            host = arg.substring(2);
        } else if (arg.startsWith("-p")) {
            port = Integer.parseInt(arg.substring(2));
        }
    }
    GearmanFunctionTest gearmanFunctionTest = new GearmanFunctionTest();

    try {
        WorkerClient worker;
        worker = new WorkerClient(host, port, "testPayload", gearmanFunctionTest );
        System.out.println(worker.testPayload(payload));                               
                worker.shutdown();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



}

public static void usage() {
    String[] usage = {
        "usage: org.gearman.example.ReverseClient [-h<host>] [-p<port>] "  
                "<string>",
        "\t-h<host> - job server host",
        "\t-p<port> - job server port",
        "\n\tExample: java org.gearman.example.ReverseClient Foo",
        "\tExample: java org.gearman.example.ReverseClient -h127.0.0.1 "  
                "-p4730 Bar", //
    };

    for (String line : usage) {
        System.err.println(line);                                           //NOPMD
    }
}

} `

Author
Account Strength
100%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
2,200
Link Karma
477
Comment Karma
1,723
Profile updated: 5 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago