/** * Query the peer for installed chaincode information * * @param peer The peer to query. * @return List of ChaincodeInfo on installed chaincode @see {@link ChaincodeInfo} * @throws InvalidArgumentException * @throws ProposalException */ public List<ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryInstalledChaincodes(peer); } catch (ProposalException e) { logger.error(format("queryInstalledChaincodes for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }
static Peer createNewInstance(String name, String grpcURL, Properties properties) throws InvalidArgumentException { return new Peer(name, grpcURL, properties); }
ListenableFuture<FabricProposalResponse.ProposalResponse> sendProposalAsync(FabricProposal.SignedProposal proposal) throws PeerException, InvalidArgumentException { checkSendProposal(proposal); if (IS_DEBUG_LEVEL) { logger.debug(format("peer.sendProposalAsync %s", toString())); } EndorserClient localEndorserClient = getEndorserClient(); try { return localEndorserClient.sendProposalAsync(proposal); } catch (Throwable t) { removeEndorserClient(true); throw t; } }
@Override public void onError(Throwable t) { ManagedChannel llmanagedChannel = managedChannel; if (llmanagedChannel != null) { try { llmanagedChannel.shutdownNow(); } catch (Exception e) { logger.warn(format("Received error on %s, attempts %d. %s shut down of grpc channel.", PeerEventServiceClient.this.toString(), peer == null ? -1 : peer.getReconnectCount(), e.getMessage()), e); } managedChannel = null; } if (!shutdown) { final long reconnectCount = peer.getReconnectCount(); if (PEER_EVENT_RECONNECTION_WARNING_RATE > 1 && reconnectCount % PEER_EVENT_RECONNECTION_WARNING_RATE == 1) { logger.warn(format("Received error on %s, attempts %d. %s", PeerEventServiceClient.this.toString(), reconnectCount, t.getMessage())); } else { logger.trace(format("Received error on %s, attempts %d. %s", PeerEventServiceClient.this.toString(), reconnectCount, t.getMessage())); } if (retry.getAndSet(false)) { peer.reconnectPeerEventServiceClient(PeerEventServiceClient.this, t); } } finishLatch.countDown(); }
/** * Construct client for accessing Peer eventing service using the existing managedChannel. */ PeerEventServiceClient(Peer peer, Endpoint endpoint, Properties properties, PeerOptions peerOptions) { this.channelBuilder = endpoint.getChannelBuilder(); this.filterBlock = peerOptions.isRegisterEventsForFilteredBlocks(); this.peer = peer; name = peer.getName(); url = peer.getUrl(); channelName = peer.getChannel().getName(); toString = "PeerEventServiceClient{" + "id: " + config.getNextID() + ", channel: " + channelName + ", peerName: " + name + ", url: " + url + "}"; this.peerOptions = peerOptions; clientTLSCertificateDigest = endpoint.getClientTLSCertificateDigest(); this.channelEventQue = peer.getChannel().getChannelEventQue(); if (null == properties) { peerEventRegistrationWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME; } else { String peerEventRegistrationWaitTime = properties.getProperty("peerEventRegistrationWaitTime", Long.toString(PEER_EVENT_REGISTRATION_WAIT_TIME)); long tempPeerWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME; try { tempPeerWaitTimeMilliSecs = Long.parseLong(peerEventRegistrationWaitTime); } catch (NumberFormatException e) { logger.warn(format("Peer event service registration %s wait time %s not parsable.", toString, peerEventRegistrationWaitTime), e); } peerEventRegistrationWaitTimeMilliSecs = tempPeerWaitTimeMilliSecs; } }
peer.setLastConnectTime(System.currentTimeMillis()); peer.resetReconnectCount(); } else { final long rec = peer.getReconnectCount(); peer.setLastConnectTime(System.currentTimeMillis()); long reconnectCount = peer.getReconnectCount(); if (reconnectCount > 1) { logger.info(format("%s reconnected after %d attempts on channel %s, peer %s, url %s", PeerEventServiceClient.this.toString(), reconnectCount, channelName, name, url)); peer.resetReconnectCount(); peer.setLastBlockSeen(blockEvent);
/** * newPeer create a new peer * * @param name * @param grpcURL to the peer's location * @return Peer * @throws InvalidArgumentException */ public Peer newPeer(String name, String grpcURL) throws InvalidArgumentException { clientCheck(); return Peer.createNewInstance(name, grpcURL, null); }
void reconnectPeerEventServiceClient(final PeerEventServiceClient failedPeerEventServiceClient, final Throwable throwable) { if (shutdown) { logger.debug(toString() + "not reconnecting PeerEventServiceClient shutdown "); return; if (ltransactionContext == null) { logger.warn(toString() + " not reconnecting PeerEventServiceClient no transaction available "); return; final ExecutorService executorService = getExecutorService(); final PeerOptions peerOptions = null != failedPeerEventServiceClient.getPeerOptions() ? failedPeerEventServiceClient.getPeerOptions() : PeerOptions.createPeerOptions();
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); disconnectedHandler = getDefaultDisconnectHandler(); connected = false; reconnectCount = new AtomicLong(0L); id = config.getNextID(); lastBlockNumber = -1L; } } // end Peer
peer.reconnectPeerEventServiceClient(this, throwable); peer.reconnectPeerEventServiceClient(this, e);
ListenableFuture<FabricProposalResponse.ProposalResponse> sendProposalAsync(FabricProposal.SignedProposal proposal) throws PeerException, InvalidArgumentException { checkSendProposal(proposal); logger.debug(format("peer.sendProposalAsync name: %s, url: %s", name, url)); EndorserClient localEndorserClient = endorserClent; //work off thread local copy. if (null == localEndorserClient || !localEndorserClient.isChannelActive()) { endorserClent = new EndorserClient(new Endpoint(url, properties).getChannelBuilder()); localEndorserClient = endorserClent; } try { return localEndorserClient.sendProposalAsync(proposal); } catch (Throwable t) { endorserClent = null; throw t; } }
final ExecutorService executorService = getExecutorService(); final PeerOptions peerOptions = null != failedPeerEventServiceClient.getPeerOptions() ? failedPeerEventServiceClient.getPeerOptions() : PeerOptions.createPeerOptions();
channelName, peer.getName(), resp.getStatusValue(), resp.getStatus(), resp.getTypeCase())); channelName, peer.getName())); peer.setLastConnectTime(System.currentTimeMillis()); peer.resetReconnectCount(); } else { channelName, peer.getName(), resp.getStatusValue(), resp.getStatus().name()))); if (typeCase == BLOCK) { logger.trace(format("Channel %s peer %s got event block hex hashcode: %016x, block number: %d", channelName, peer.getName(), resp.getBlock().hashCode(), resp.getBlock().getHeader().getNumber())); } else { logger.trace(format("Channel %s peer %s got event block hex hashcode: %016x, block number: %d", channelName, peer.getName(), resp.getFilteredBlock().hashCode(), resp.getFilteredBlock().getNumber())); peer.setLastConnectTime(System.currentTimeMillis()); long reconnectCount = peer.getReconnectCount(); if (reconnectCount > 1) { peer.resetReconnectCount(); peer.setLastBlockSeen(blockEvent); channelName, peer.getName(), typeCase.name(), typeCase.getNumber())); channelName, peer.getName(), typeCase.name(), typeCase.getNumber())));
/** * Construct client for accessing Peer eventing service using the existing managedChannel. */ PeerEventServiceClient(Peer peer, Endpoint endpoint, Properties properties, PeerOptions peerOptions) { this.channelBuilder = endpoint.getChannelBuilder(); this.filterBlock = peerOptions.isRegisterEventsForFilteredBlocks(); this.peer = peer; name = peer.getName(); url = peer.getUrl(); channelName = peer.getChannel().getName(); this.peerOptions = peerOptions; clientTLSCertificateDigest = endpoint.getClientTLSCertificateDigest(); this.channelEventQue = peer.getChannel().getChannelEventQue(); if (null == properties) { peerEventRegistrationWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME; } else { this.properties = properties; String peerEventRegistrationWaitTime = properties.getProperty("peerEventRegistrationWaitTime", Long.toString(PEER_EVENT_REGISTRATION_WAIT_TIME)); long tempPeerWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME; try { tempPeerWaitTimeMilliSecs = Long.parseLong(peerEventRegistrationWaitTime); } catch (NumberFormatException e) { logger.warn(format("Peer event service registration %s wait time %s not parsable.", name, peerEventRegistrationWaitTime), e); } peerEventRegistrationWaitTimeMilliSecs = tempPeerWaitTimeMilliSecs; } }
@Override public void onError(Throwable t) { ManagedChannel llmanagedChannel = managedChannel; if (llmanagedChannel != null) { llmanagedChannel.shutdownNow(); managedChannel = null; } if (!shutdown) { final long reconnectCount = peer.getReconnectCount(); if (PEER_EVENT_RECONNECTION_WARNING_RATE > 1 && reconnectCount % PEER_EVENT_RECONNECTION_WARNING_RATE == 1) { logger.warn(format("Received error on peer eventing service on channel %s, peer %s, url %s, attempts %d. %s", channelName, name, url, reconnectCount, t.getMessage())); } else { logger.trace(format("Received error on peer eventing service on channel %s, peer %s, url %s, attempts %d. %s", channelName, name, url, reconnectCount, t.getMessage())); } peer.reconnectPeerEventServiceClient(PeerEventServiceClient.this, t); } finishLatch.countDown(); }
return Peer.createNewInstance(name, grpcURL, properties);
void reconnectPeerEventServiceClient(final PeerEventServiceClient failedPeerEventServiceClient, final Throwable throwable) { if (shutdown) { logger.debug(toString() + "not reconnecting PeerEventServiceClient shutdown "); return; if (ltransactionContext == null) { logger.warn(toString() + " not reconnecting PeerEventServiceClient no transaction available "); return; final ExecutorService executorService = getExecutorService(); final PeerOptions peerOptions = null != failedPeerEventServiceClient.getPeerOptions() ? failedPeerEventServiceClient.getPeerOptions() : PeerOptions.createPeerOptions();
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); disconnectedHandler = getDefaultDisconnectHandler(); } } // end Peer
peer.reconnectPeerEventServiceClient(this, throwable); peer.reconnectPeerEventServiceClient(this, e);
/** * Query the joined channels for peers * * @param peer the peer to query * @return A set of strings with the names of the channels the peer has joined. * @throws InvalidArgumentException * @throws ProposalException */ public Set<String> queryChannels(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } //Run this on a system channel. try { Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryChannels(peer); } catch (InvalidArgumentException e) { throw e; //dont log } catch (ProposalException e) { logger.error(format("queryChannels for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }