Java Code Examples for com.google.gwt.user.client.rpc.AsyncCallback#onFailure()

The following examples show how to use com.google.gwt.user.client.rpc.AsyncCallback#onFailure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RetryLocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Request listPuzzles(final AsyncCallback<PuzzleDescriptor[]> callback) {
    return super.listPuzzles( new AsyncCallback<PuzzleDescriptor[]>(){

        @Override
        public void onFailure(Throwable caught) {
            if(caught instanceof InvocationException){
                RetryLocalStorageServiceProxy.super.listPuzzles(callback);
            } else {
                callback.onFailure(caught);
            }
        }

        @Override
        public void onSuccess(PuzzleDescriptor[] result) {
            callback.onSuccess(result);
        }

    });
}
 
Example 2
Source File: RetryLocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Request findPuzzle(final Long puzzleId, final AsyncCallback<Puzzle> callback) {
    return super.findPuzzle(puzzleId, new AsyncCallback<Puzzle>(){

        @Override
        public void onFailure(Throwable caught) {
            if(caught instanceof InvocationException ){
                RetryLocalStorageServiceProxy.super.findPuzzle(puzzleId, callback);
            } else {
                callback.onFailure(caught);
            }
        }

        @Override
        public void onSuccess(Puzzle result) {
            callback.onSuccess(result);
        }

    });
}
 
Example 3
Source File: BlockActivity.java    From bitcoin-transaction-explorer with MIT License 6 votes vote down vote up
@Override
protected void doLookup(final BlockPlace place, final AsyncCallback<BlockInformation> callback) {
  switch (place.getType()) {
  case HEIGHT:
    service.getBlockInformationFromHeight(Integer.parseInt(place.getPayload()), callback);
    break;
  case ID:
    service.getBlockInformationFromHash(place.getPayload(), callback);
    break;
  case LAST:
    service.getBlockInformationLast(callback);
    break;
  case RAW:
    final byte[] computeDoubleSHA256 = ComputeUtil.computeDoubleSHA256(Hex.decode(place.getPayload()));
    ArrayUtil.reverse(computeDoubleSHA256);
    final String blockHash = Str.toString(Hex.encode(computeDoubleSHA256));
    service.getBlockInformationFromHash(blockHash, callback);
    break;
  default:
    callback.onFailure(new IllegalStateException("No support lookup for type: " + place.getType().name()));
    return;
  }
}
 
Example 4
Source File: MineActivity.java    From bitcoin-transaction-explorer with MIT License 6 votes vote down vote up
@Override
protected void doLookup(final MinePlace place, final AsyncCallback<BlockInformation> callback) {
  switch (place.getType()) {
  case HEIGHT:
    service.getBlockInformationFromHeight(Integer.parseInt(place.getPayload()), callback);
    break;
  case ID:
    service.getBlockInformationFromHash(place.getPayload(), callback);
    break;
  case LAST:
    service.getBlockInformationLast(new MorphCallback<BlockInformation, BlockInformation>(callback) {
      @Override
      protected BlockInformation morphResult(final BlockInformation result) {
        final TransactionInformation ti = new TransactionInformation();
        ti.setRawHex(SEAN_OUTPOST_HASH_160);
        result.setCoinbaseInformation(ti);
        return result;
      }
    });
    break;
  default:
    callback.onFailure(new IllegalStateException("No support lookup for type: " + place.getType().name()));
    return;
  }
}
 
Example 5
Source File: DefaultCommandController.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onFailure(Throwable caught) {
	if (caught instanceof StatusCodeException) {
		GWT.reportUncaughtException(caught);
	} else {
		for (Request request : this.requests) {
			if (request.param.getCallbacks().isEmpty()) {
				GWT.reportUncaughtException(caught);
			}
			for (AsyncCallback requestCallback : request.param.getCallbacks()) {
				requestCallback.onFailure(caught);
			}
		}
		if (this.callback != null) {
			this.callback.onFailure(caught);
		}
	}
}
 
Example 6
Source File: TestDMRHandler.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public DispatchRequest execute(DMRAction action, AsyncCallback<DMRResponse> callback) {


    try {
        DispatchResult result = new SimpleDispatcher(DOMAIN_API_URL).execute(action.getOperation());
        callback.onSuccess(new DMRResponse(result.getResponseText(), APPLICATION_DMR_ENCODED) );

    } catch (Exception e) {
        callback.onFailure(e);
    }

    return new DispatchRequest()
    {
        @Override
        public void cancel() {

        }

        @Override
        public boolean isPending() {
            return false;
        }
    };
}
 
Example 7
Source File: LocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
private void saveInternal(Long listingId, Puzzle puzzle, final AsyncCallback callback){
    try{
        WindowContext.INSTANCE.put(listingId.toString(), CODEC.serialize(puzzle));
        WindowContext.INSTANCE.flush();
    } catch(final Exception e){
        callback.onFailure(e);
    }
   
    callback.onSuccess(null);
}
 
Example 8
Source File: LocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
private void loadInternal(Long listingId, AsyncCallback<Puzzle> callback){
    try {
        GWT.log("Load internal", null);
        String data = WindowContext.INSTANCE.get(listingId.toString());
        GWT.log(data, null);
        callback.onSuccess(CODEC.deserialize(data));
    } catch (SerializationException ex) {
        callback.onFailure(ex);
    }
}
 
Example 9
Source File: FreeTimeParser.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void getData(String source, AsyncCallback<List<FreeTime>> callback) {
	try {
		callback.onSuccess(parseFreeTime(source));
	} catch (IllegalArgumentException e) {
		callback.onFailure(e);
	}
}
 
Example 10
Source File: FilterBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(String text, AsyncCallback<Chip> callback) {
	if (iValidate) {
		for (Chip chip: iValues)
			if (chip.getValue().equals(text)) {
				callback.onSuccess(chip);
				return;
			}
		callback.onFailure(new Exception("Unknown value " + text + "."));
	} else {
		callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()));
	}
}
 
Example 11
Source File: GwtRpcProxy.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
   protected <T> Request doInvoke(ResponseReader responseReader, final String methodName, RpcStatsContext statsContext, String requestData, final AsyncCallback<T> callback) {
	return super.doInvoke(responseReader, methodName, statsContext, requestData, new AsyncCallback<T>() {
		@Override
		public void onFailure(Throwable caught) {
			UniTimeNotifications.error("Request " + methodName.replace("_Proxy", "") + " failed: " + caught.getMessage(), caught);
			callback.onFailure(caught);
		}
		@Override
		public void onSuccess(T result) {
			callback.onSuccess(result);
		}
	});
}
 
Example 12
Source File: ScriptActivity.java    From bitcoin-transaction-explorer with MIT License 5 votes vote down vote up
@Override
protected void doLookup(final ScriptPlace place, final AsyncCallback<ScriptInformation> callback) {
  final MorphCallback<TransactionInformation, ScriptInformation> morphCallback = new MorphCallback<TransactionInformation, ScriptInformation>(callback) {
    @Override
    protected ScriptInformation morphResult(final TransactionInformation result) {
      // Parse the outpoint transaction in full
      final Transaction tx = ParseUtil.getTransactionFromHex(result.getRawHex());

      // Parse the ScriptSig from the place
      final ScriptEntity scriptSig = ScriptParseUtil.parseScript(Hex.decode(place.getScriptSig()));

      // Construct the OutPoint from the retrieved transaction index in the place
      final TransactionOutPoint outPoint = new TransactionOutPoint();
      outPoint.setReferenceTransaction(tx.getTransactionId());
      outPoint.setIndex(place.getOutpointIndex());

      // Get the OutPoint's pubKeySig from the parsed transaction
      final TransactionOutput pubKeySig = tx.getOutputs().get(place.getOutpointIndex());

      // Construct the ScriptInformation and return it
      final ScriptInformation information = new ScriptInformation();
      information.setPubKeySig(pubKeySig);
      information.setScriptSig(scriptSig);
      information.setOutpoint(outPoint);
      return information;
    }
  };

  switch (place.getType()) {
  case ID:
    service.getTransactionInformation(place.getOutpointTransaction(), morphCallback);
    break;
  default:
    callback.onFailure(new IllegalStateException("No support lookup for type: " + place.getType().name()));
    return;
  }
}
 
Example 13
Source File: StaticDispatcher.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <A extends Action<R>, R extends Result> DispatchRequest execute(A action, AsyncCallback<R> callback) {
    this.action = action;
    if (failure != null) {
        callback.onFailure(failure);
    } else {
        if (results.isEmpty()) {
            throw new IllegalStateException("Results stack is empty. Please call " + StaticDispatcher.class.getSimpleName() + ".push(result) to push expected results!");
        }
        callback.onSuccess((R) results.pop());
    }
    return null;
}
 
Example 14
Source File: DispatchAsyncImpl.java    From core with GNU Lesser General Public License v2.1 3 votes vote down vote up
@Override
public <A extends Action<R>, R extends Result> DispatchRequest execute(A action, AsyncCallback<R> callback) {

    ActionHandler<A,R> handler = registry.resolve(action);

    if(null==handler)
        callback.onFailure(new IllegalStateException("No handler for type "+action.getType()));

    return handler.execute(action, callback, Collections.unmodifiableMap(properties));
}