public StringBuilder appendFields( ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) { super.appendFields(locator, buffer, strategy); { List<String> theServerURI; theServerURI = (((this.serverURI != null) && (!this.serverURI.isEmpty())) ? this.getServerURI() : null); strategy.appendField(locator, this, "serverURI", buffer, theServerURI); } { Boolean theWebSocket; theWebSocket = this.isWebSocket(); strategy.appendField(locator, this, "webSocket", buffer, theWebSocket); } { String theClientID; theClientID = this.getClientID(); strategy.appendField(locator, this, "clientID", buffer, theClientID); } { UserCredentials theUserCredentials; theUserCredentials = this.getUserCredentials(); strategy.appendField(locator, this, "userCredentials", buffer, theUserCredentials); } { SimpleMqttMessage theLastWillAndTestament; theLastWillAndTestament = this.getLastWillAndTestament(); strategy.appendField(locator, this, "lastWillAndTestament", buffer, theLastWillAndTestament); } { Boolean theCleanSession; theCleanSession = this.isCleanSession(); strategy.appendField(locator, this, "cleanSession", buffer, theCleanSession); } { Integer theConnectionTimeout; theConnectionTimeout = this.getConnectionTimeout(); strategy.appendField(locator, this, "connectionTimeout", buffer, theConnectionTimeout); } { Integer theKeepAliveInterval; theKeepAliveInterval = this.getKeepAliveInterval(); strategy.appendField(locator, this, "keepAliveInterval", buffer, theKeepAliveInterval); } { SecureSocketSettings theSSL; theSSL = this.getSSL(); strategy.appendField(locator, this, "ssl", buffer, theSSL); } { ReconnectionSettings theReconnectionSettings; theReconnectionSettings = this.getReconnectionSettings(); strategy.appendField(locator, this, "reconnectionSettings", buffer, theReconnectionSettings); } return buffer; }
/** * Launch a pair of threads to handle bi-directional stream communication. * * @param localSocket Local socket. * @param remoteEndPoint ConnectionDetails. The remote <code>EndPoint</code> to forward output to. * This is also used in the logging and filter output. * @param clientEndPoint The <code>EndPoint</code> to be used in the logging and filter output. * This may well differ from the <code>localSocket</code> binding. * @param isSecure Whether the connection is secure. * @exception IOException If an I/O error occurs. */ protected final void launchThreadPair( Socket localSocket, EndPoint remoteEndPoint, EndPoint clientEndPoint, boolean isSecure) throws IOException { final Socket remoteSocket = m_socketFactory.createClientSocket(remoteEndPoint); final ConnectionDetails connectionDetails = new ConnectionDetails(clientEndPoint, remoteEndPoint, isSecure); new FilteredStreamThread( localSocket.getInputStream(), new OutputStreamFilterTee( connectionDetails, remoteSocket.getOutputStream(), m_requestFilter, m_requestColour)); new FilteredStreamThread( remoteSocket.getInputStream(), new OutputStreamFilterTee( connectionDetails.getOtherEnd(), localSocket.getOutputStream(), m_responseFilter, m_responseColour)); }
public byte[] handle(ConnectionDetails connectionDetails, byte[] buffer, int bytesRead) throws java.io.IOException { final StringBuffer stringBuffer = new StringBuffer(); boolean inHex = false; for (int i = 0; i < bytesRead; i++) { final int value = (buffer[i] & 0xFF); // If it's ASCII, print it as a char. if (value == '\r' || value == '\n' || (value >= ' ' && value <= '~')) { if (inHex) { stringBuffer.append(']'); inHex = false; } stringBuffer.append((char) value); } else { // else print the value if (!inHex) { stringBuffer.append('['); inHex = true; } if (value <= 0xf) { // Where's "HexNumberFormatter?" stringBuffer.append("0"); } stringBuffer.append(Integer.toHexString(value).toUpperCase()); } } m_out.println("------ " + connectionDetails.getDescription() + " ------"); m_out.println(stringBuffer); try { int connections; Scanner scanner = new Scanner(new FileInputStream(JSSEConstants.STATS_FILE_LOCATION)); connections = scanner.nextInt(); connections++; scanner.close(); FileWriter fw = new FileWriter(JSSEConstants.STATS_FILE_LOCATION); fw.write("" + connections); fw.close(); } catch (Exception e) { e.printStackTrace(); } return null; }
@AfterSuite(groups = {"init"}) public static void tearDownAfterSuite() throws Exception { System.out.println("CLOSING CASSANDRA CONNECTION"); if (dynamicCluster) { System.out.println("Stopping nodes"); clusterHasBuilt = false; try { ccmBridge.forceStop(); System.out.println("Discarding cluster"); ccmBridge.remove(); HOST = System.getProperty("host", ConnectionDetails.getHost()); } catch (Exception e) { System.out.println("Silent error discarding cluster"); } } }
public class BuildCluster { private static final Logger logger = LoggerFactory.getLogger(BuildCluster.class); public static String HOST = System.getProperty("host", ConnectionDetails.getHost()); public static CCMBridge ccmBridge = null; public static Cluster cluster = null; public static Session session = null; public static Cluster cluster2 = null; public static Session session2 = null; public static Session sessionFluks = null; public static boolean clusterHasBuilt = false; public static boolean dynamicCluster = false; @BeforeSuite(groups = {"init"}) public static void setUpBeforeSuite() throws Exception { System.setProperty("cassandra.version", "3.0.4"); System.setProperty("ipprefix", "127.0.0."); if (!isClusterActive()) { ccmBridge = CCMBridge.create( "jdbc_cluster" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()), 1, 1); ccmBridge.waitForUp(1); // ccmBridge.waitForUp(2); HOST = CCMBridge.ipOfNode(1); dynamicCluster = true; } else { HOST = "127.0.0.1"; } clusterHasBuilt = true; } @AfterSuite(groups = {"init"}) public static void tearDownAfterSuite() throws Exception { System.out.println("CLOSING CASSANDRA CONNECTION"); if (dynamicCluster) { System.out.println("Stopping nodes"); clusterHasBuilt = false; try { ccmBridge.forceStop(); System.out.println("Discarding cluster"); ccmBridge.remove(); HOST = System.getProperty("host", ConnectionDetails.getHost()); } catch (Exception e) { System.out.println("Silent error discarding cluster"); } } } public static boolean isClusterActive() { try { Builder builder = Cluster.builder() .withQueryOptions( new QueryOptions() .setConsistencyLevel(ConsistencyLevel.QUORUM) .setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL)); cluster = builder.addContactPoint("127.0.0.1").build(); session = cluster.connect(); return true; } catch (Exception e) { return false; } } }
public void connectionClosed(ConnectionDetails connectionDetails) { m_out.println("--- " + connectionDetails.getDescription() + " closed --"); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy strategy) { final Object draftCopy = ((target == null) ? createNewInstance() : target); super.copyTo(locator, draftCopy, strategy); if (draftCopy instanceof MqttConnectionDetails) { final MqttConnectionDetails copy = ((MqttConnectionDetails) draftCopy); if ((this.serverURI != null) && (!this.serverURI.isEmpty())) { List<String> sourceServerURI; sourceServerURI = (((this.serverURI != null) && (!this.serverURI.isEmpty())) ? this.getServerURI() : null); @SuppressWarnings("unchecked") List<String> copyServerURI = ((List<String>) strategy.copy( LocatorUtils.property(locator, "serverURI", sourceServerURI), sourceServerURI)); copy.serverURI = null; if (copyServerURI != null) { List<String> uniqueServerURIl = copy.getServerURI(); uniqueServerURIl.addAll(copyServerURI); } } else { copy.serverURI = null; } if (this.webSocket != null) { Boolean sourceWebSocket; sourceWebSocket = this.isWebSocket(); Boolean copyWebSocket = ((Boolean) strategy.copy( LocatorUtils.property(locator, "webSocket", sourceWebSocket), sourceWebSocket)); copy.setWebSocket(copyWebSocket); } else { copy.webSocket = null; } if (this.clientID != null) { String sourceClientID; sourceClientID = this.getClientID(); String copyClientID = ((String) strategy.copy( LocatorUtils.property(locator, "clientID", sourceClientID), sourceClientID)); copy.setClientID(copyClientID); } else { copy.clientID = null; } if (this.userCredentials != null) { UserCredentials sourceUserCredentials; sourceUserCredentials = this.getUserCredentials(); UserCredentials copyUserCredentials = ((UserCredentials) strategy.copy( LocatorUtils.property(locator, "userCredentials", sourceUserCredentials), sourceUserCredentials)); copy.setUserCredentials(copyUserCredentials); } else { copy.userCredentials = null; } if (this.lastWillAndTestament != null) { SimpleMqttMessage sourceLastWillAndTestament; sourceLastWillAndTestament = this.getLastWillAndTestament(); SimpleMqttMessage copyLastWillAndTestament = ((SimpleMqttMessage) strategy.copy( LocatorUtils.property( locator, "lastWillAndTestament", sourceLastWillAndTestament), sourceLastWillAndTestament)); copy.setLastWillAndTestament(copyLastWillAndTestament); } else { copy.lastWillAndTestament = null; } if (this.cleanSession != null) { Boolean sourceCleanSession; sourceCleanSession = this.isCleanSession(); Boolean copyCleanSession = ((Boolean) strategy.copy( LocatorUtils.property(locator, "cleanSession", sourceCleanSession), sourceCleanSession)); copy.setCleanSession(copyCleanSession); } else { copy.cleanSession = null; } if (this.connectionTimeout != null) { Integer sourceConnectionTimeout; sourceConnectionTimeout = this.getConnectionTimeout(); Integer copyConnectionTimeout = ((Integer) strategy.copy( LocatorUtils.property(locator, "connectionTimeout", sourceConnectionTimeout), sourceConnectionTimeout)); copy.setConnectionTimeout(copyConnectionTimeout); } else { copy.connectionTimeout = null; } if (this.keepAliveInterval != null) { Integer sourceKeepAliveInterval; sourceKeepAliveInterval = this.getKeepAliveInterval(); Integer copyKeepAliveInterval = ((Integer) strategy.copy( LocatorUtils.property(locator, "keepAliveInterval", sourceKeepAliveInterval), sourceKeepAliveInterval)); copy.setKeepAliveInterval(copyKeepAliveInterval); } else { copy.keepAliveInterval = null; } if (this.ssl != null) { SecureSocketSettings sourceSSL; sourceSSL = this.getSSL(); SecureSocketSettings copySSL = ((SecureSocketSettings) strategy.copy(LocatorUtils.property(locator, "ssl", sourceSSL), sourceSSL)); copy.setSSL(copySSL); } else { copy.ssl = null; } if (this.reconnectionSettings != null) { ReconnectionSettings sourceReconnectionSettings; sourceReconnectionSettings = this.getReconnectionSettings(); ReconnectionSettings copyReconnectionSettings = ((ReconnectionSettings) strategy.copy( LocatorUtils.property( locator, "reconnectionSettings", sourceReconnectionSettings), sourceReconnectionSettings)); copy.setReconnectionSettings(copyReconnectionSettings); } else { copy.reconnectionSettings = null; } } return draftCopy; }