public TopologyBroker(final int nodeId, final String host, final int port) { this.nodeId = nodeId; this.host = host; this.port = port; address = new SocketAddress(host, port); }
public TopologyBroker(final int nodeId, final String host, final int port) { this.nodeId = nodeId; this.host = host; this.port = port; address = new SocketAddress(host, port); }
public SocketAddress toSocketAddress() { return new SocketAddress(host, port); }
public SocketAddress toSocketAddress() { return new SocketAddress(host, port); }
public SocketAddress toSocketAddress() { return new SocketAddress(host, port); }
@Override public SocketAddress next() { return new SocketAddress(host, nextPort()); }
/** * Tries to parse a address string to create a new socket address. * * @param address the address string with format host:port * @return the created socket address * @throws IllegalArgumentException if the address cannot be parsed */ public static SocketAddress from(final String address) { final String[] parts = address.split(":", 2); if (parts.length != 2) { throw new IllegalArgumentException( "Address has to be in format host:port but was: " + address); } final int port; final String portString = parts[1]; try { port = Integer.parseInt(portString); } catch (final NumberFormatException e) { throw new IllegalArgumentException( "Port of address '" + address + "' has to be a number but was: " + portString); } return new SocketAddress(parts[0], port); } }
@Override public SocketAddress next() { return new SocketAddress(host, nextPort()); }
public ControlledTopologyManager() { this( new NodeInfo( 0, new SocketAddress("0.0.0.0", 0), new SocketAddress("0.0.0.0", 1), new SocketAddress("0.0.0.0", 2), new SocketAddress("0.0.0.0", 3)), 1, 1, 1); }
/** * Tries to parse a address string to create a new socket address. * * @param address the address string with format host:port * @return the created socket address * @throws IllegalArgumentException if the address cannot be parsed */ public static SocketAddress from(final String address) { final String[] parts = address.split(":", 2); if (parts.length != 2) { throw new IllegalArgumentException( "Address has to be in format host:port but was: " + address); } final int port; final String portString = parts[1]; try { port = Integer.parseInt(portString); } catch (final NumberFormatException e) { throw new IllegalArgumentException( "Port of address '" + address + "' has to be a number but was: " + portString); } return new SocketAddress(parts[0], port); } }
public ControlledTopologyManager() { this( new NodeInfo( 0, new SocketAddress("0.0.0.0", 0), new SocketAddress("0.0.0.0", 1), new SocketAddress("0.0.0.0", 2), new SocketAddress("0.0.0.0", 3)), 1, 1, 1); }
public static NodeInfo readNodeInfo(int offset, DirectBuffer directBuffer) { final int nodeId = directBuffer.getInt(offset, ByteOrder.LITTLE_ENDIAN); offset += SIZE_OF_INT; final SocketAddress managementApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, managementApi); final SocketAddress clientApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, clientApi); final SocketAddress replicationApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, replicationApi); final SocketAddress subscriptionApi = new SocketAddress(); readSocketAddress(offset, directBuffer, subscriptionApi); return new NodeInfo(nodeId, clientApi, managementApi, replicationApi, subscriptionApi); }
public static NodeInfo readNodeInfo(int offset, DirectBuffer directBuffer) { final int nodeId = directBuffer.getInt(offset, ByteOrder.LITTLE_ENDIAN); offset += SIZE_OF_INT; final SocketAddress managementApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, managementApi); final SocketAddress clientApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, clientApi); final SocketAddress replicationApi = new SocketAddress(); offset = readSocketAddress(offset, directBuffer, replicationApi); final SocketAddress subscriptionApi = new SocketAddress(); readSocketAddress(offset, directBuffer, subscriptionApi); return new NodeInfo(nodeId, clientApi, managementApi, replicationApi, subscriptionApi); }
@Override public RemoteAddressImpl register(SocketAddress inetSocketAddress) { RemoteAddressImpl result = getByAddress(inetSocketAddress); if (result == null) { synchronized (this) { result = getByAddress( inetSocketAddress, RemoteAddressImpl.STATE_ACTIVE | RemoteAddressImpl.STATE_INACTIVE); if (result == null) { final int prevSize = size; final int newSize = prevSize + 1; final RemoteAddressImpl remoteAddress = new RemoteAddressImpl(prevSize, new SocketAddress(inetSocketAddress)); final RemoteAddressImpl[] newAddresses = new RemoteAddressImpl[newSize]; System.arraycopy(index, 0, newAddresses, 0, prevSize); newAddresses[remoteAddress.getStreamId()] = remoteAddress; this.index = newAddresses; this.size = newSize; // publish result = remoteAddress; } else { if (result.isInAnyState(RemoteAddressImpl.STATE_INACTIVE)) { result.activate(); } } onAddressAddedConsumer.accept(result); } } return result; }
@Override public RemoteAddressImpl register(SocketAddress inetSocketAddress) { RemoteAddressImpl result = getByAddress(inetSocketAddress); if (result == null) { synchronized (this) { result = getByAddress( inetSocketAddress, RemoteAddressImpl.STATE_ACTIVE | RemoteAddressImpl.STATE_INACTIVE); if (result == null) { final int prevSize = size; final int newSize = prevSize + 1; final RemoteAddressImpl remoteAddress = new RemoteAddressImpl(prevSize, new SocketAddress(inetSocketAddress)); final RemoteAddressImpl[] newAddresses = new RemoteAddressImpl[newSize]; System.arraycopy(index, 0, newAddresses, 0, prevSize); newAddresses[remoteAddress.getStreamId()] = remoteAddress; this.index = newAddresses; this.size = newSize; // publish result = remoteAddress; } else { if (result.isInAnyState(RemoteAddressImpl.STATE_INACTIVE)) { result.activate(); } } onAddressAddedConsumer.accept(result); } } return result; }
public void onServerChannelOpened(SocketChannel serverChannel) { SocketAddress socketAddress = null; try { socketAddress = new SocketAddress((InetSocketAddress) serverChannel.getRemoteAddress()); } catch (IOException e) { try { serverChannel.close(); } catch (IOException e1) { return; } } RemoteAddressImpl remoteAddress = remoteAddressList.getByAddress(socketAddress); if (remoteAddress != null) { // make sure to generate a new stream id remoteAddressList.retire(remoteAddress); } remoteAddress = remoteAddressList.register(socketAddress); final TransportChannel ch = channelFactory.buildServerChannel( this, remoteAddress, transportContext.getMessageMaxLength(), transportContext.getReceiveHandler(), serverChannel); onChannelConnected(ch); }
public void onServerChannelOpened(SocketChannel serverChannel) { SocketAddress socketAddress = null; try { socketAddress = new SocketAddress((InetSocketAddress) serverChannel.getRemoteAddress()); } catch (IOException e) { try { serverChannel.close(); } catch (IOException e1) { return; } } RemoteAddressImpl remoteAddress = remoteAddressList.getByAddress(socketAddress); if (remoteAddress != null) { // make sure to generate a new stream id remoteAddressList.retire(remoteAddress); } remoteAddress = remoteAddressList.register(socketAddress); final TransportChannel ch = channelFactory.buildServerChannel( this, remoteAddress, transportContext.getMessageMaxLength(), transportContext.getReceiveHandler(), serverChannel); onChannelConnected(ch); }
public BrokerClusterStateImpl( final TopologyResponseDto topologyDto, final BiConsumer<Integer, SocketAddress> endpointRegistry) { clusterSize = topologyDto.getClusterSize(); partitionsCount = topologyDto.getPartitionsCount(); replicationFactor = topologyDto.getReplicationFactor(); topologyDto .brokers() .forEach( b -> { final int nodeId = b.getNodeId(); endpointRegistry.accept( nodeId, new SocketAddress(bufferAsString(b.getHost()), b.getPort())); brokers.add(nodeId); b.partitionStates() .forEach( p -> { final int partitionId = p.getPartitionId(); partitions.add(partitionId); if (p.isLeader()) { partitionLeaders.put(partitionId, nodeId); } }); }); }