public static boolean isSameHost(TransportConfiguration tc1, TransportConfiguration tc2) { if (NettyConnectorFactory.class.getName().equals(tc1.getFactoryClassName())) { String host1 = tc1.getParams().get("host") != null ? tc1.getParams().get("host").toString() : TransportConstants.DEFAULT_HOST; String host2 = tc2.getParams().get("host") != null ? tc2.getParams().get("host").toString() : TransportConstants.DEFAULT_HOST; String port1 = String.valueOf(tc1.getParams().get("port") != null ? tc1.getParams().get("port") : TransportConstants.DEFAULT_PORT); String port2 = String.valueOf(tc2.getParams().get("port") != null ? tc2.getParams().get("port") : TransportConstants.DEFAULT_PORT); return host1.equals(host2) && port1.equals(port2); } else if ("org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory".equals(tc1.getFactoryClassName())) { String serverId1 = tc1.getParams().get("serverId") != null ? tc1.getParams().get("serverId").toString() : "0"; String serverId2 = tc2.getParams().get("serverId") != null ? tc2.getParams().get("serverId").toString() : "0"; return serverId1.equals(serverId2); } return false; }
public static URI getUri(TransportConfiguration[] configurations) throws URISyntaxException { String host = "0"; if (configurations != null && configurations.length > 0) { TransportConfiguration configuration = configurations[0]; Map<String, Object> params = configuration.getParams(); host = params.get("serverId") == null ? host : params.get("serverId").toString(); } return new URI(SchemaConstants.VM, null, host, -1, null, null, null); } }
if (configuration.get(TransportConstants.PORT_PROP_NAME).equals(cfg.getParams().get(TransportConstants.PORT_PROP_NAME))) { if (hostParam.equals(cfg.getParams().get(TransportConstants.HOST_PROP_NAME))) { result = true; break; } else { if (isLocalhost((String) configuration.get(TransportConstants.HOST_PROP_NAME)) && isLocalhost((String) cfg.getParams().get(TransportConstants.HOST_PROP_NAME))) { result = true; break; } else if (cfg.getParams().get(TransportConstants.HOST_PROP_NAME) == null) { result = true; break;
protected Connector createConnector(ConnectorFactory connectorFactory, TransportConfiguration configuration) { return connectorFactory.createConnector(configuration.getParams(), new DelegatingBufferHandler(), this, closeExecutor, threadPool, scheduledThreadPool, clientProtocolManager); }
/** * Replaces class name and parameter names to HornetQ values. */ private static TransportConfiguration convertTransport(TransportConfiguration tc) { if (tc != null) { String className = tc.getFactoryClassName().replace("org.apache.activemq.artemis", "org.hornetq").replace("ActiveMQ", "HornetQ"); return new TransportConfiguration(className, convertParameters(tc.getParams()), tc.getName()); } return tc; }
public static URI getURI(String query, TransportConfiguration[] staticConnectors) throws Exception { if (staticConnectors == null || staticConnectors.length < 1) { throw new Exception(); } StringBuilder fragment = new StringBuilder(); for (int i = 1; i < staticConnectors.length; i++) { TransportConfiguration connector = staticConnectors[i]; Map<String, Object> params = escapeIPv6Host(connector.getParams()); URI extraUri = new URI(SchemaConstants.TCP, null, getHost(params), getPort(params), null, createQuery(params, null), null); if (i > 1) { fragment.append(","); } fragment.append(extraUri.toASCIIString()); } Map<String, Object> params = escapeIPv6Host(staticConnectors[0].getParams()); return new URI(SchemaConstants.TCP, null, getHost(params), getPort(params), null, createQuery(params, query), fragment.toString()); }
@Override public void setBackupConnector(final TransportConfiguration live, final TransportConfiguration backUp) { Connector localConnector = connector; // if the connector has never been used (i.e. the getConnection hasn't been called yet), we will need // to create a connector just to validate if the parameters are ok. // so this will create the instance to be used on the isEquivalent check if (localConnector == null) { localConnector = connectorFactory.createConnector(currentConnectorConfig.getParams(), new DelegatingBufferHandler(), this, closeExecutor, threadPool, scheduledThreadPool, clientProtocolManager); } if (localConnector.isEquivalent(live.getParams()) && backUp != null && !localConnector.isEquivalent(backUp.getParams())) { if (logger.isDebugEnabled()) { logger.debug("Setting up backup config = " + backUp + " for live = " + live); } backupConfig = backUp; } else { if (logger.isDebugEnabled()) { logger.debug("ClientSessionFactoryImpl received backup update for live/backup pair = " + live + " / " + backUp + " but it didn't belong to " + currentConnectorConfig); } } }
public TransportConfiguration getBackupForConnector(final Connector connector) { for (TopologyMemberImpl member : topology.values()) { if (member.getLive() != null && connector.isEquivalent(member.getLive().getParams())) { return member.getBackup(); } } return null; }
@Override public String toURI() { TransportConfiguration liveConnector = getLive(); Map<String, Object> props = liveConnector.getParams(); String host = ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, "localhost", props); int port = ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 0, props); return "tcp://" + host + ":" + port; }
/** * Adapt the transport configuration by replacing the factoryClassName corresponding to an HornetQ's NettyConnectorFactory * by the Artemis-based implementation. */ @Override public TransportConfiguration adaptTransportConfiguration(TransportConfiguration tc) { if (tc == null) { return null; } String factoryClassName = tc.getFactoryClassName(); if (factoryClassName.equals("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory")) { factoryClassName = NettyConnectorFactory.class.getName(); } TransportConfiguration newConfig = new TransportConfiguration(factoryClassName, tc.getParams(), tc.getName(), tc.getExtraParams()); return newConfig; }
public URI toBackupURI() { TransportConfiguration backupConnector = getBackup(); if (backupConnector == null) { return null; } Map<String, Object> props = backupConnector.getParams(); String host = ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, "localhost", props); int port = ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 0, props); boolean sslEnabled = ConfigurationHelper.getBooleanProperty(TransportConstants.SSL_ENABLED_PROP_NAME, false, props); try { return new URI("tcp://" + host + ":" + port + "?" + TransportConstants.SSL_ENABLED_PROP_NAME + "=" + sslEnabled); } catch (URISyntaxException e) { return null; } }
public static URI getUri(TransportConfiguration[] configurations) throws URISyntaxException { String host = "0"; if (configurations != null && configurations.length > 0) { TransportConfiguration configuration = configurations[0]; Map<String, Object> params = configuration.getParams(); host = params.get("serverId") == null ? host : params.get("serverId").toString(); } return new URI(SchemaConstants.VM, null, host, -1, null, null, null); } }
public static URI getUri(TransportConfiguration[] configurations) throws URISyntaxException { String host = "0"; if (configurations != null && configurations.length > 0) { TransportConfiguration configuration = configurations[0]; Map<String, Object> params = configuration.getParams(); host = params.get("serverId") == null ? host : params.get("serverId").toString(); } return new URI(SchemaConstants.VM, null, host, -1, null, null, null); } }
public static int getServer(Connection connection) { ClientSession session = ((ActiveMQConnection) connection).getInitialSession(); TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration(); String port = (String) transportConfiguration.getParams().get("port"); return Integer.valueOf(port) - 61616; }
public static Connection getServerConnection(int server, Connection... connections) { for (Connection connection : connections) { ClientSession session = ((ActiveMQConnection) connection).getInitialSession(); TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration(); String port = (String) transportConfiguration.getParams().get("port"); if (Integer.valueOf(port) == server + 61616) { return connection; } } return null; }
public static int getEncodeSize(TransportConfiguration config) { int size = BufferHelper.sizeOfNullableSimpleString(config.getName()) + BufferHelper.sizeOfSimpleString(config.getFactoryClassName()); size += DataConstants.SIZE_INT; // number of params for (Entry<String, Object> param : config.getParams().entrySet()) { size += BufferHelper.sizeOfSimpleString(param.getKey()); size += BufferHelper.sizeOfSimpleString(param.getValue().toString()); } return size; }
@Override public String toURI() { TransportConfiguration liveConnector = getLive(); Map<String, Object> props = liveConnector.getParams(); String host = ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, "localhost", props); int port = ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 0, props); return "tcp://" + host + ":" + port; }
public TransportConfiguration getBackupForConnector(final Connector connector) { for (TopologyMemberImpl member : topology.values()) { if (member.getLive() != null && connector.isEquivalent(member.getLive().getParams())) { return member.getBackup(); } } return null; }
protected Connector createConnector(ConnectorFactory connectorFactory, TransportConfiguration configuration) { Connector connector = connectorFactory.createConnector(configuration.getParams(), new DelegatingBufferHandler(), this, closeExecutor, threadPool, scheduledThreadPool, clientProtocolManager); if (connector instanceof NettyConnector) { NettyConnector nettyConnector = (NettyConnector) connector; if (nettyConnector.getConnectTimeoutMillis() < 0) { nettyConnector.setConnectTimeoutMillis((int)serverLocator.getConnectionTTL()); } } return connector; }
protected Connector createConnector(ConnectorFactory connectorFactory, TransportConfiguration configuration) { Connector connector = connectorFactory.createConnector(configuration.getParams(), new DelegatingBufferHandler(), this, closeExecutor, threadPool, scheduledThreadPool, clientProtocolManager); if (connector instanceof NettyConnector) { NettyConnector nettyConnector = (NettyConnector) connector; if (nettyConnector.getConnectTimeoutMillis() < 0) { nettyConnector.setConnectTimeoutMillis((int)serverLocator.getConnectionTTL()); } } return connector; }