当前位置: 首页>>代码示例>>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;未经允许,请勿转载。