void unsetChannel() { logger.debug(toString() + " unset " + channel); channel = null; }
private static PeerEventingServiceDisconnected getDefaultDisconnectHandler() { return new PeerEventingServiceDisconnected() { //default. @Override public synchronized void disconnected(final PeerEventingServiceDisconnectEvent event) { BlockEvent lastBlockEvent = event.getLatestBLockReceived(); Throwable thrown = event.getExceptionThrown(); long sleepTime = PEER_EVENT_RETRY_WAIT_TIME; if (thrown instanceof PeerEventingServiceException) { // means we connected and got an error or connected but timout waiting on the response // not going away.. sleep longer. sleepTime = Math.min(5000L, PEER_EVENT_RETRY_WAIT_TIME + event.getReconnectCount() * 100L); //wait longer if we connected. //don't flood server. } Long startBlockNumber = null; if (null != lastBlockEvent) { startBlockNumber = lastBlockEvent.getBlockNumber(); } try { Thread.sleep(sleepTime); } catch (InterruptedException e) { logger.warn(toString() + " " + e.getMessage()); } try { event.reconnect(startBlockNumber); } catch (TransactionException e) { logger.warn(toString() + " " + e.getMessage()); } } }; }
synchronized void setLastBlockSeen(BlockEvent lastBlockSeen) { connected = true; long newLastBlockNumber = lastBlockSeen.getBlockNumber(); // overkill but make sure. if (lastBlockNumber < newLastBlockNumber) { lastBlockNumber = newLastBlockNumber; this.lastBlockEvent = lastBlockSeen; if (IS_TRACE_LEVEL) { logger.trace(toString() + " last block seen: " + lastBlockNumber); } } }
@Override protected void finalize() throws Throwable { if (!shutdown) { logger.debug(toString() + " finalized without previous shutdown."); } shutdown(true); super.finalize(); }
private synchronized void removeEndorserClient(boolean force) { EndorserClient localEndorserClient = endorserClent; endorserClent = null; if (null != localEndorserClient) { if (IS_DEBUG_LEVEL) { logger.debug(format("Peer %s removing endorser client %s, isActive: %b", toString(), localEndorserClient.toString(), localEndorserClient.isChannelActive())); } try { localEndorserClient.shutdown(force); } catch (Exception e) { logger.warn(toString() + " error message: " + e.getMessage()); } } }
private void checkSendProposal(FabricProposal.SignedProposal proposal) throws PeerException, InvalidArgumentException { if (shutdown) { throw new PeerException(format("%s was shutdown.", toString())); } if (proposal == null) { throw new PeerException(toString() + " Proposal is null"); } Exception e = checkGrpcUrl(url); if (e != null) { throw new InvalidArgumentException("Bad peer url.", e); } }
synchronized void shutdown(boolean force) { if (shutdown) { return; } final String me = toString(); logger.debug(me + " is shutting down."); shutdown = true; channel = null; lastBlockEvent = null; lastBlockNumber = -1L; removeEndorserClient(force); PeerEventServiceClient lpeerEventingClient = peerEventingClient; peerEventingClient = null; if (null != lpeerEventingClient) { // PeerEventServiceClient peerEventingClient1 = peerEventingClient; logger.debug(me + " is shutting down " + lpeerEventingClient); lpeerEventingClient.shutdown(force); } logger.debug(me + " is shut down."); }
ListenableFuture<Protocol.Response> sendDiscoveryRequestAsync(Protocol.SignedRequest discoveryRequest) throws PeerException, InvalidArgumentException { logger.debug(format("peer.sendDiscoveryRequstAsync %s", toString())); EndorserClient localEndorserClient = getEndorserClient(); try { return localEndorserClient.sendDiscoveryRequestAsync(discoveryRequest); } catch (Throwable t) { removeEndorserClient(true); throw t; } }
/** * Set the channel the peer is on. * * @param channel */ void setChannel(Channel channel) throws InvalidArgumentException { if (null != this.channel) { throw new InvalidArgumentException(format("Can not add peer %s to channel %s because it already belongs to channel %s.", name, channel.getName(), this.channel.getName())); } logger.debug(format("%s setting channel to %s, from %s", toString(), "" + channel, "" + this.channel)); this.channel = channel; this.channelName = channel.getName(); }
private synchronized EndorserClient getEndorserClient() { EndorserClient localEndorserClient = endorserClent; //work off thread local copy. if (null == localEndorserClient || !localEndorserClient.isChannelActive()) { if (IS_TRACE_LEVEL) { logger.trace(format("Channel %s creating new endorser client %s", channelName, toString())); } Endpoint endpoint = Endpoint.createEndpoint(url, properties); foundClientTLSCertificateDigest = true; clientTLSCertificateDigest = endpoint.getClientTLSCertificateDigest(); localEndorserClient = new EndorserClient(channelName, name, url, endpoint.getChannelBuilder()); if (IS_DEBUG_LEVEL) { logger.debug(format("%s created new %s", toString(), localEndorserClient.toString())); } endorserClent = localEndorserClient; } return localEndorserClient; }
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; } }
Peer(String name, String grpcURL, Properties properties) throws InvalidArgumentException { reconnectCount = new AtomicLong(0L); id = config.getNextID(); Exception e = checkGrpcUrl(grpcURL); if (e != null) { throw new InvalidArgumentException("Bad peer url.", e); } if (StringUtil.isNullOrEmpty(name)) { throw new InvalidArgumentException("Invalid name for peer"); } this.url = grpcURL; this.name = name; this.properties = properties == null ? null : (Properties) properties.clone(); //keep our own copy. logger.debug("Created " + toString()); }
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;
serviceDiscoveryException = null; try { logger.debug(format("Channel %s doing discovery for chaincodes on peer: %s", channelName, serviceDiscoveryPeer.toString())); logger.warn(format("Channel %s peer %s requires mutual tls for service discovery.", channelName, serviceDiscoveryPeer.toString())); continue; logger.debug(format("Channel %s peer %s sending chaincode query request", channelName, serviceDiscoveryPeer.toString())); final Protocol.Response response = serviceDiscoveryPeer.sendDiscoveryRequestAsync(sr).get(SERVICE_DISCOVERY_WAITTIME, TimeUnit.MILLISECONDS); if (IS_TRACE_LEVEL && null != diagnosticFileDumper) { // dump protobuf we get diagnosticFileDumper.createDiagnosticProtobufFile(response.toByteArray()))); logger.debug(format("Channel %s peer %s completed chaincode query request", channelName, serviceDiscoveryPeer.toString())); serviceDiscoveryPeer.hasConnected(); logger.warn(format("Service discovery error on peer %s. Error: %s", serviceDiscoveryPeer.toString(), e.getMessage())); serviceDiscoveryException = e; } catch (Exception e) { logger.warn(format("Service discovery error on peer %s. Error: %s", serviceDiscoveryPeer.toString(), e.getMessage())); serviceDiscoveryException = new ServiceDiscoveryException(e);
logger.info(format("Channel %s doing discovery with peer: %s", channelName, serviceDiscoveryPeer.toString())); logger.warn(format("Channel %s peer: %s error during service discovery %s", channelName, serviceDiscoveryPeer.toString(), queryResult.getError().getContent())); continue; logger.warn(format("Channel %s peer %s service discovery error %s", channelName, serviceDiscoveryPeer.toString(), queryResult2.getError().getContent())); continue;
void unsetChannel() { logger.debug(toString() + " unset " + channel); channel = null; }
@Override protected void finalize() throws Throwable { if (!shutdown) { logger.debug(toString() + " finalized without previous shutdown."); } shutdown(true); super.finalize(); }
synchronized void setLastBlockSeen(BlockEvent lastBlockSeen) { connected = true; long newLastBlockNumber = lastBlockSeen.getBlockNumber(); // overkill but make sure. if (lastBlockNumber < newLastBlockNumber) { lastBlockNumber = newLastBlockNumber; this.lastBlockEvent = lastBlockSeen; if (IS_TRACE_LEVEL) { logger.trace(toString() + " last block seen: " + lastBlockNumber); } } }
private void checkSendProposal(FabricProposal.SignedProposal proposal) throws PeerException, InvalidArgumentException { if (shutdown) { throw new PeerException(format("%s was shutdown.", toString())); } if (proposal == null) { throw new PeerException(toString() + " Proposal is null"); } Exception e = checkGrpcUrl(url); if (e != null) { throw new InvalidArgumentException("Bad peer url.", e); } }
ListenableFuture<Protocol.Response> sendDiscoveryRequestAsync(Protocol.SignedRequest discoveryRequest) throws PeerException, InvalidArgumentException { logger.debug(format("peer.sendDiscoveryRequstAsync %s", toString())); EndorserClient localEndorserClient = getEndorserClient(); try { return localEndorserClient.sendDiscoveryRequestAsync(discoveryRequest); } catch (Throwable t) { removeEndorserClient(true); throw t; } }