@Override public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { Socket socket = null; PrintWriter writer = null; try { socket = pool.borrowObject(address); writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8), true); for (String formattedResult : messageFormatter.formatResults(results, server)) { log.debug("OpenTSDB Message: {}", formattedResult); writer.write("put " + formattedResult + "\n"); } } catch (ConnectException e) { log.error("Error while connecting to OpenTSDB", e); } finally { if (writer != null && writer.checkError()) { log.error("Error writing to OpenTSDB, clearing OpenTSDB socket pool"); pool.invalidateObject(address, socket); } else { pool.returnObject(address, socket); } } }
/** * Connect channel. * * @param serverAddress the server address * @return the channel */ private Channel doConnect(String serverAddress) { Channel channelToServer = channels.get(serverAddress); if (null != channelToServer && channelToServer.isActive()) { return channelToServer; } try { RegisterTMRequest registerTransactionManagerRequest = new RegisterTMRequest( applicationId, transactionServiceGroup); poolKeyMap.putIfAbsent(serverAddress, new NettyPoolKey(getTransactionRole(), serverAddress, registerTransactionManagerRequest)); channelToServer = nettyClientKeyPool.borrowObject(poolKeyMap.get(serverAddress)); } catch (Exception exx) { LOGGER.error("get channel from pool error.", exx); throw new FrameworkException("can not register TM,err:" + exx.getMessage()); } return channelToServer; }
message.setResourceIds(resourceIds); channelFromPool = nettyClientKeyPool.borrowObject(poolKeyMap.get(serverAddress)); } catch (Exception exx) { LOGGER.error(FrameworkErrorCode.RegistRM.errCode, "register RM failed.", exx);
@Override public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { Socket socket = null; PrintWriter writer = null; try { socket = pool.borrowObject(address); writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8), true); List<String> typeNames = this.getTypeNames(); for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + result.getEpoch() / 1000 + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } } finally { if (writer != null && writer.checkError()) { log.error("Error writing to Graphite, clearing Graphite socket pool"); pool.invalidateObject(address, socket); } else { pool.returnObject(address, socket); } } }
public PayrollInterfaceModuleConnectionIdentifierAdapter acquireConnection(PayrollInterfaceModuleConnectionKey key) throws Exception { return ((PayrollInterfaceModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
public AbsenceModuleConnectionIdentifierAdapter acquireConnection(AbsenceModuleConnectionKey key) throws Exception { return ((AbsenceModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
public Object borrowObject(Object key) throws Exception, NoSuchElementException, IllegalStateException { return pool.borrowObject(key); }
public PerformanceModuleConnectionIdentifierAdapter acquireConnection(PerformanceModuleConnectionKey key) throws Exception { return ((PerformanceModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
public BenefitsModuleConnectionIdentifierAdapter acquireConnection(BenefitsModuleConnectionKey key) throws Exception { return ((BenefitsModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
public PayrollModuleConnectionIdentifierAdapter acquireConnection(PayrollModuleConnectionKey key) throws Exception { return ((PayrollModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
public StaffingModuleConnectionIdentifierAdapter acquireConnection(StaffingModuleConnectionKey key) throws Exception { return ((StaffingModuleConnectionIdentifierAdapter) connectionPool.borrowObject(key)); }
/** * Lookup a socket in the list of dispatcher sockets but don't create a new * socket * * @param endpoint */ DatagramSocket getSocket(ImmutableEndpoint endpoint) throws Exception { return (DatagramSocket) dispatcherSocketsPool.borrowObject(endpoint); }
private EventSyncConnection getTCPNettyClient() { eventSyncConnectionPoolFactory = EventSyncConnectionPoolManager.getConnectionPool(); EventSyncConnection eventSyncConnection = null; try { eventSyncConnection = (EventSyncConnection) eventSyncConnectionPoolFactory.borrowObject(HAConstants.ACTIVE_NODE_CONNECTION_POOL_ID); } catch (Exception e) { log.warn("Error in obtaining a tcp connection to the passive node. Hence not sending events to the " + "passive node. " + e.getMessage()); } return eventSyncConnection; }
public GroovyPoolEntry borrowShell(String script) throws Exception { GroovyPoolKey key = new GroovyPoolKey(script); GroovyPoolEntry entry; try { entry = pool.borrowObject(key); return entry; } catch (Exception e) { logger.error("An error occurred while borrowing script: " + script, e); throw e; } }
public boolean contains(String pattern, String input) { Pattern compiled = null; try { compiled = (Pattern)_pool.borrowObject(pattern); return compiled.matcher(input).find(); } catch (Exception e) { throw new ApplicationRuntimeException(e); } finally { try { _pool.returnObject(pattern, compiled); } catch (Throwable t) { } } }
public boolean matches(String pattern, String input) { Pattern compiled = null; try { compiled = (Pattern)_pool.borrowObject(pattern); return compiled.matcher(input).matches(); } catch (Exception e) { throw new ApplicationRuntimeException(e); } finally { try { _pool.returnObject(pattern, compiled); } catch (Throwable t) { } } }
private EventSyncConnection getTCPConnection() { deploymentConfig = StreamProcessorDataHolder.getDeploymentConfig(); GenericKeyedObjectPool tcpConnectionPool = EventSyncConnectionPoolManager.getConnectionPool(); EventSyncConnection eventSyncConnection = null; try { eventSyncConnection = (EventSyncConnection) tcpConnectionPool.borrowObject(HAConstants.ACTIVE_NODE_CONNECTION_POOL_ID); tcpConnectionPool.returnObject(HAConstants.ACTIVE_NODE_CONNECTION_POOL_ID, eventSyncConnection); } catch (Exception e) { log.error("Error in getting a connection to the Passive node. " + e.getMessage()); } return eventSyncConnection; }
@Override public Object borrowObject(final Object key) throws Exception { final long start = System.nanoTime(); final DatabasePoolBorrowEvent event = new DatabasePoolBorrowEvent(getDatabaseInfo(name)); try { return MonitoredGenericKeyedObjectPool.super.borrowObject(key); } finally { event.setElapsedTimeNano(System.nanoTime() - start); SystemInstance.get().fireEvent(event); } }
private Object getClient() throws DataEndpointException { try { return transportPool.borrowObject(getDataEndpointConfiguration().getPublisherKey()); } catch (Exception e) { throw new DataEndpointException("Cannot borrow client for " + getDataEndpointConfiguration().getPublisherKey(), e); } }
private Object getClient() throws DataEndpointException { try { return transportPool.borrowObject(getDataEndpointConfiguration().getPublisherKey()); } catch (Exception e) { throw new DataEndpointException("Cannot borrow client for " + getDataEndpointConfiguration().getPublisherKey(), e); } }