Esempio n. 1
0
 public byte[] digest(byte[] input) {
   String function = DigestFunction.class.getCanonicalName();
   String uniqueId = null;
   byte[] algoNameBytes = ALGO_NAME.getBytes();
   byte[] digestParms = new byte[input.length + algoNameBytes.length + 1];
   System.arraycopy(algoNameBytes, 0, digestParms, 0, algoNameBytes.length);
   digestParms[algoNameBytes.length] = '\0';
   System.arraycopy(input, 0, digestParms, algoNameBytes.length + 1, input.length);
   GearmanJob job = GearmanJobImpl.createJob(function, digestParms, uniqueId);
   Future<GearmanJobResult> f = client.submit(job);
   GearmanJobResult jr = null;
   try {
     jr = f.get();
   } catch (Exception e) {
     e.printStackTrace(); // NOPMD
   }
   if (jr == null) {
     return new byte[0];
   } else {
     if (jr.jobSucceeded()) {
       return jr.getResults();
     } else {
       System.err.println(ByteUtils.fromUTF8Bytes(jr.getExceptions())); // NOPMD
       return new byte[0];
     }
   }
 }
Esempio n. 2
0
 public void shutdown() throws IllegalStateException {
   if (client == null) {
     throw new IllegalStateException("No client to shutdown");
   }
   client.shutdown();
 }
Esempio n. 3
0
 public DigestClient(GearmanJobServerConnection conn) {
   client = new GearmanClientImpl();
   client.addJobServer(conn);
 }