Java Code Examples for org.jboss.netty.channel.Channel.getLocalAddress()

The following are Jave code examples for showing how to use getLocalAddress() of the org.jboss.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: traccar-service   File: MeiligaoProtocolDecoder.java   View Source Code Vote up 5 votes
private String getServer(Channel channel) {
    String server = Context.getConfig().getString(getProtocolName() + ".server");
    if (server == null) {
        InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress();
        server = address.getAddress().getHostAddress() + ":" + address.getPort();
    }
    return server;
}
 
Example 2
Project: https-github.com-apache-zookeeper   File: ClientCnxnSocketNetty.java   View Source Code Vote up 4 votes
@Override
SocketAddress getLocalSocketAddress() {
    Channel copiedChanRef = channel;
    return (copiedChanRef == null) ? null : copiedChanRef.getLocalAddress();
}
 
Example 3
Project: athena   File: BgpControllerImplTest.java   View Source Code Vote up 4 votes
@Before
public void setUp() throws Exception {
    peer1 = new BgpPeerTest(version, asNumber,
            holdTime, bgpId, isLargeAsCapabilitySet,
            capabilityTlv);
    peer2 = new BgpPeerTest(version, asNumber,
            holdTime, bgpId, isLargeAsCapabilitySet,
            capabilityTlv);

    bgpControllerImpl = new BgpControllerImpl();

    // NOTE: We use port 0 to bind on any available port
    bgpControllerImpl.controller().setBgpPortNum();
    bgpControllerImpl.activate();

    Channel serverChannel = TestUtils.getField(bgpControllerImpl.controller(),
                                              "serverChannel");
    SocketAddress socketAddress = serverChannel.getLocalAddress();
    InetSocketAddress inetSocketAddress =
       (InetSocketAddress) socketAddress;
    InetAddress connectToAddress = InetAddresses.forString("127.0.0.1");
    connectToSocket = new InetSocketAddress(connectToAddress,
                   inetSocketAddress.getPort());

    bgpControllerImpl.getConfig().setRouterId("1.1.1.1");
    bgpControllerImpl.getConfig().setAsNumber(200);
    bgpControllerImpl.getConfig().setHoldTime((short) 120);
    bgpControllerImpl.getConfig().setState(BgpCfg.State.IP_AS_CONFIGURED);

    bgpControllerImpl.getConfig().addPeer("127.0.0.1", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.9", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.33", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.10", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.20", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.30", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.40", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.50", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.60", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.70", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.80", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.90", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.91", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.92", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.99", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.94", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.95", 200);
    bgpControllerImpl.getConfig().addPeer("127.0.0.35", 200);
}
 
Example 4
Project: athena   File: BgpSessionManagerTest.java   View Source Code Vote up 4 votes
@Before
public void setUp() throws Exception {
    peer1 = new TestBgpPeer(BGP_PEER1_ID);
    peer2 = new TestBgpPeer(BGP_PEER2_ID);
    peer3 = new TestBgpPeer(BGP_PEER3_ID);
    peers.clear();
    peers.add(peer1);
    peers.add(peer2);
    peers.add(peer3);

    //
    // Setup the BGP Session Manager to test, and start listening for BGP
    // connections.
    //
    bgpSessionManager = new BgpSessionManager();

    routeService = createNiceMock(RouteAdminService.class);
    replay(routeService);
    bgpSessionManager.routeService = routeService;

    // NOTE: We use port 0 to bind on any available port
    ComponentContext componentContext = createMock(ComponentContext.class);
    getDictionaryMock(componentContext);
    replay(componentContext);
    bgpSessionManager.activate(componentContext);

    // Get the port number the BGP Session Manager is listening on
    Channel serverChannel = TestUtils.getField(bgpSessionManager,
                                               "serverChannel");
    SocketAddress socketAddress = serverChannel.getLocalAddress();
    InetSocketAddress inetSocketAddress =
        (InetSocketAddress) socketAddress;
    InetAddress connectToAddress = InetAddresses.forString("127.0.0.1");
    connectToSocket = new InetSocketAddress(connectToAddress,
                                            inetSocketAddress.getPort());

    //
    // Setup the AS Paths
    //
    ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
    byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
    ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
    segmentAsNumbers1.add(65010L);
    segmentAsNumbers1.add(65020L);
    segmentAsNumbers1.add(65030L);
    BgpRouteEntry.PathSegment pathSegment1 =
        new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
    pathSegments.add(pathSegment1);
    asPathShort = new BgpRouteEntry.AsPath(new ArrayList<>(pathSegments));
    //
    byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
    ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
    segmentAsNumbers2.add(65041L);
    segmentAsNumbers2.add(65042L);
    segmentAsNumbers2.add(65043L);
    BgpRouteEntry.PathSegment pathSegment2 =
        new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
    pathSegments.add(pathSegment2);
    //
    asPathLong = new BgpRouteEntry.AsPath(pathSegments);
}