當前位置: 首頁>>代碼示例>>Java>>正文


Java GuardedBy類代碼示例

本文整理匯總了Java中net.jcip.annotations.GuardedBy的典型用法代碼示例。如果您正苦於以下問題:Java GuardedBy類的具體用法?Java GuardedBy怎麽用?Java GuardedBy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GuardedBy類屬於net.jcip.annotations包,在下文中一共展示了GuardedBy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: receiveChannelOpen

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveChannelOpen() throws VerificationException {
    checkState(step == InitStep.WAITING_FOR_CHANNEL_OPEN || (step == InitStep.WAITING_FOR_INITIATE && storedChannel != null), step);
    log.info("Got CHANNEL_OPEN message, ready to pay");

    boolean wasInitiated = true;
    if (step == InitStep.WAITING_FOR_INITIATE) {
        // We skipped the initiate step, because a previous channel that's still valid was resumed.
        wasInitiated  = false;
        switch (majorVersion) {
            case 1:
                state = new PaymentChannelV1ClientState(storedChannel, wallet);
                break;
            case 2:
                state = new PaymentChannelV2ClientState(storedChannel, wallet);
                break;
            default:
                throw new IllegalStateException("Invalid version number " + majorVersion);
        }
    }
    step = InitStep.CHANNEL_OPEN;
    // channelOpen should disable timeouts, but
    // TODO accomodate high latency between PROVIDE_CONTRACT and here
    conn.channelOpen(wasInitiated);
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:26,代碼來源:PaymentChannelClient.java

示例2: receiveClose

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(lock.isHeldByCurrentThread());
    if (msg.hasSettlement()) {
        Transaction settleTx = wallet.getParams().getDefaultSerializer().makeTransaction(msg.getSettlement().getTx().toByteArray());
        log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
        // TODO: set source
        if (state != null && state().isSettlementTransaction(settleTx)) {
            // The wallet has a listener on it that the state object will use to do the right thing at this
            // point (like watching it for confirmations). The tx has been checked by now for syntactical validity
            // and that it correctly spends the multisig contract.
            wallet.receivePending(settleTx, null);
        }
    } else {
        log.info("CLOSE message received without settlement tx");
    }
    if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    else
        conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
    step = InitStep.CHANNEL_CLOSED;
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:23,代碼來源:PaymentChannelClient.java

示例3: receiveRefundMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveRefundMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(majorVersion == 1);
    checkState(step == InitStep.WAITING_ON_UNSIGNED_REFUND && msg.hasProvideRefund());
    log.info("Got refund transaction, returning signature");

    Protos.ProvideRefund providedRefund = msg.getProvideRefund();
    state = new PaymentChannelV1ServerState(broadcaster, wallet, myKey, expireTime);
    // We can cast to V1 state since this state is only used in the V1 protocol
    byte[] signature = ((PaymentChannelV1ServerState) state)
            .provideRefundTransaction(wallet.getParams().getDefaultSerializer().makeTransaction(providedRefund.getTx().toByteArray()),
                    providedRefund.getMultisigKey().toByteArray());

    step = InitStep.WAITING_ON_CONTRACT;

    Protos.ReturnRefund.Builder returnRefundBuilder = Protos.ReturnRefund.newBuilder()
            .setSignature(ByteString.copyFrom(signature));

    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setReturnRefund(returnRefundBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.RETURN_REFUND)
            .build());
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:24,代碼來源:PaymentChannelServer.java

示例4: receiveContractMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(majorVersion == 1 || majorVersion == 2);
    checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract());
    log.info("Got contract, broadcasting and responding with CHANNEL_OPEN");
    final Protos.ProvideContract providedContract = msg.getProvideContract();

    if (majorVersion == 2) {
        state = new PaymentChannelV2ServerState(broadcaster, wallet, myKey, expireTime);
        checkState(providedContract.hasClientKey(), "ProvideContract didn't have a client key in protocol v2");
        ((PaymentChannelV2ServerState)state).provideClientKey(providedContract.getClientKey().toByteArray());
    }

    //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation?
    final Transaction contract = wallet.getParams().getDefaultSerializer().makeTransaction(providedContract.getTx().toByteArray());
    step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE;
    state.provideContract(contract)
            .addListener(new Runnable() {
                @Override
                public void run() {
                    multisigContractPropogated(providedContract, contract.getHash());
                }
            }, Threading.SAME_THREAD);
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:25,代碼來源:PaymentChannelServer.java

示例5: settlePayment

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
    // Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
    // close() on us here below via the stored channel state.
    // TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
    channelSettling = true;
    ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
    ListenableFuture<Transaction> result;
    if (keyFuture != null) {
        result = Futures.transform(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
            @Override
            public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
                return state.close(userKey);
            }
        });
    } else {
        result = state.close();
    }
    Futures.addCallback(result, new FutureCallback<Transaction>() {
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:20,代碼來源:PaymentChannelServer.java

示例6: settlePayment

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
    // Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
    // close() on us here below via the stored channel state.
    // TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
    channelSettling = true;
    ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
    ListenableFuture<Transaction> result;
    if (keyFuture != null) {
        result = Futures.transformAsync(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
            @Override
            public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
                return state.close(userKey);
            }
        });
    } else {
        result = state.close();
    }
    Futures.addCallback(result, new FutureCallback<Transaction>() {
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:20,代碼來源:PaymentChannelServer.java

示例7: receiveChannelOpen

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveChannelOpen() throws VerificationException {
    checkState(step == InitStep.WAITING_FOR_CHANNEL_OPEN || (step == InitStep.WAITING_FOR_INITIATE && storedChannel != null), step);
    log.info("Got CHANNEL_OPEN message, ready to pay");

    boolean wasInitiated = true;
    if (step == InitStep.WAITING_FOR_INITIATE) {
        // We skipped the initiate step, because a previous channel that's still valid was resumed.
        wasInitiated  = false;
        state = new PaymentChannelClientState(storedChannel, wallet);
    }
    step = InitStep.CHANNEL_OPEN;
    // channelOpen should disable timeouts, but
    // TODO accomodate high latency between PROVIDE_CONTRACT and here
    conn.channelOpen(wasInitiated);
}
 
開發者ID:HashEngineering,項目名稱:namecoinj,代碼行數:17,代碼來源:PaymentChannelClient.java

示例8: receiveClose

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(lock.isHeldByCurrentThread());
    if (msg.hasSettlement()) {
        Transaction settleTx = new Transaction(wallet.getParams(), msg.getSettlement().getTx().toByteArray());
        log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
        // TODO: set source
        if (state != null && state().isSettlementTransaction(settleTx)) {
            // The wallet has a listener on it that the state object will use to do the right thing at this
            // point (like watching it for confirmations). The tx has been checked by now for syntactical validity
            // and that it correctly spends the multisig contract.
            wallet.receivePending(settleTx, null);
        }
    } else {
        log.info("CLOSE message received without settlement tx");
    }
    if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    else
        conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
    step = InitStep.CHANNEL_CLOSED;
}
 
開發者ID:HashEngineering,項目名稱:namecoinj,代碼行數:23,代碼來源:PaymentChannelClient.java

示例9: receiveRefundMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveRefundMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_UNSIGNED_REFUND && msg.hasProvideRefund());
    log.info("Got refund transaction, returning signature");

    Protos.ProvideRefund providedRefund = msg.getProvideRefund();
    state = new PaymentChannelServerState(broadcaster, wallet, myKey, expireTime);
    byte[] signature = state.provideRefundTransaction(new Transaction(wallet.getParams(), providedRefund.getTx().toByteArray()),
            providedRefund.getMultisigKey().toByteArray());

    step = InitStep.WAITING_ON_CONTRACT;

    Protos.ReturnRefund.Builder returnRefundBuilder = Protos.ReturnRefund.newBuilder()
            .setSignature(ByteString.copyFrom(signature));

    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setReturnRefund(returnRefundBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.RETURN_REFUND)
            .build());
}
 
開發者ID:HashEngineering,項目名稱:namecoinj,代碼行數:21,代碼來源:PaymentChannelServer.java

示例10: receiveContractMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract());
    log.info("Got contract, broadcasting and responding with CHANNEL_OPEN");
    final Protos.ProvideContract providedContract = msg.getProvideContract();

    //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation?
    final Transaction multisigContract = new Transaction(wallet.getParams(), providedContract.getTx().toByteArray());
    step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE;
    state.provideMultiSigContract(multisigContract)
            .addListener(new Runnable() {
                @Override
                public void run() {
                    multisigContractPropogated(providedContract, multisigContract.getHash());
                }
            }, Threading.SAME_THREAD);
}
 
開發者ID:HashEngineering,項目名稱:namecoinj,代碼行數:18,代碼來源:PaymentChannelServer.java

示例11: authenticate

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
void authenticate(HttpClient client) throws IOException {
    if (id == null || id.isEmpty() || password == null || password.isEmpty()) {
        invalid = "Unable to re-authenticate expired token: missing appleId/ password.";

    } else {
        try {
            Auth auth = Auth.from(client, id, password);

            if (auth.dsPrsID().equals(token.auth().dsPrsID())) {
                token = Token.from(auth);

            } else {
                logger.error("-- reauthentication() > mismatched dsPrsID: {} > {}",
                        token.auth().dsPrsID(), auth.dsPrsID());
                invalid = "Unable to re-authenticate expired token: account mismatch.";
            }
        } catch (HttpResponseException ex) {
            if (ex.getStatusCode() == 401) {
                invalid = "Unable to re-authenticate expired token: invalid appleId/ password.";
            }
        }
    }

    testIsInvalid();
}
 
開發者ID:horrorho,項目名稱:LiquidDonkey,代碼行數:27,代碼來源:Authenticator.java

示例12: moveFile

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
/**
 * Move a file from one AWS S3 folder to another.
 *
 * @param blobStore         the blob store
 * @param sourceKey         the file source location
 * @param destinationFolder the destination folder
 * @return the destination key of the moved file
 * @throws KeyNotFoundException if a key is not found
 */
@GuardedBy("ThreadLocal blobStore")
private String moveFile(final BlobStore blobStore, final String sourceKey,
                        final String destinationFolder) throws KeyNotFoundException {

  final Blob blob = blobStore.getBlob(config.getS3().getBucket(), sourceKey);

  if (blob != null) {

    final String destinationKey = destinationFolder + "/"
        + sourceKey.substring(sourceKey.lastIndexOf('/') + 1);

    blob.getMetadata().setName(destinationKey);
    blobStore.putBlob(config.getS3().getBucket(), blob);
    blobStore.removeBlob(config.getS3().getBucket(), sourceKey);
    return destinationKey;

  } else {
    throw new KeyNotFoundException(sourceKey, config.getS3().getBucket(), "Error while moving file.");
  }
}
 
開發者ID:Pixxis,項目名稱:zoufzouf,代碼行數:30,代碼來源:LogSlurper.java

示例13: receiveUpdatePaymentMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveUpdatePaymentMessage(Protos.UpdatePayment msg, boolean sendAck) throws VerificationException, ValueOutOfRangeException, InsufficientMoneyException {
    log.info("Got a payment update");

    BigInteger lastBestPayment = state.getBestValueToMe();
    final BigInteger refundSize = BigInteger.valueOf(msg.getClientChangeValue());
    boolean stillUsable = state.incrementPayment(refundSize, msg.getSignature().toByteArray());
    BigInteger bestPaymentChange = state.getBestValueToMe().subtract(lastBestPayment);

    if (bestPaymentChange.signum() > 0)
        conn.paymentIncrease(bestPaymentChange, state.getBestValueToMe());

    if (sendAck) {
        Protos.TwoWayChannelMessage.Builder ack = Protos.TwoWayChannelMessage.newBuilder();
        ack.setType(Protos.TwoWayChannelMessage.MessageType.PAYMENT_ACK);
        conn.sendToClient(ack.build());
    }

    if (!stillUsable) {
        log.info("Channel is now fully exhausted, closing/initiating settlement");
        settlePayment(CloseReason.CHANNEL_EXHAUSTED);
    }
}
 
開發者ID:HashEngineering,項目名稱:megacoinj,代碼行數:24,代碼來源:PaymentChannelServer.java

示例14: receiveContractMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract());
    log.info("Got contract, broadcasting and responding with CHANNEL_OPEN");
    Protos.ProvideContract providedContract = msg.getProvideContract();

    //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation?
    final Transaction multisigContract = new Transaction(wallet.getParams(), providedContract.getTx().toByteArray());
    step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE;
    state.provideMultiSigContract(multisigContract)
            .addListener(new Runnable() {
                @Override
                public void run() {
                    multisigContractPropogated(multisigContract.getHash());
                }
            }, Threading.SAME_THREAD);
}
 
開發者ID:sserrano44,項目名稱:bitcoinj-watcher-service,代碼行數:18,代碼來源:PaymentChannelServer.java

示例15: receiveUpdatePaymentMessage

import net.jcip.annotations.GuardedBy; //導入依賴的package包/類
@GuardedBy("lock")
private void receiveUpdatePaymentMessage(Protos.UpdatePayment msg, boolean sendAck) throws VerificationException, ValueOutOfRangeException, InsufficientMoneyException {
    log.info("Got a payment update");

    BigInteger lastBestPayment = state.getBestValueToMe();
    final BigInteger refundSize = BigInteger.valueOf(msg.getClientChangeValue());
    boolean stillUsable = state.incrementPayment(refundSize, msg.getSignature().toByteArray());
    BigInteger bestPaymentChange = state.getBestValueToMe().subtract(lastBestPayment);

    if (bestPaymentChange.compareTo(BigInteger.ZERO) > 0)
        conn.paymentIncrease(bestPaymentChange, state.getBestValueToMe());

    if (sendAck) {
        Protos.TwoWayChannelMessage.Builder ack = Protos.TwoWayChannelMessage.newBuilder();
        ack.setType(Protos.TwoWayChannelMessage.MessageType.PAYMENT_ACK);
        conn.sendToClient(ack.build());
    }

    if (!stillUsable) {
        log.info("Channel is now fully exhausted, closing/initiating settlement");
        settlePayment(CloseReason.CHANNEL_EXHAUSTED);
    }
}
 
開發者ID:10xEngineer,項目名稱:My-Wallet-Android,代碼行數:24,代碼來源:PaymentChannelServer.java


注:本文中的net.jcip.annotations.GuardedBy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。