Search in sources :

Example 1 with ProviderMessageRouter

use of com.weibo.api.motan.transport.ProviderMessageRouter in project motan by weibocom.

the class YarRpcProtocolTest method testInitRequestRouter.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInitRequestRouter() {
    YarRpcProtocol protocol = new YarRpcProtocol();
    URL url = new URL("motan", "localhost", 8002, "urlpath");
    Provider provider = new DefaultProvider(null, url, MessageHandler.class);
    ProviderMessageRouter router = protocol.initRequestRouter(url, provider);
    assertNotNull(router);
    URL url2 = new URL("motan", "localhost", 8003, "urlpath2");
    Provider provider2 = new DefaultProvider(null, url2, MessageHandler.class);
    ProviderMessageRouter router2 = protocol.initRequestRouter(url2, provider2);
    assertNotNull(router2);
    assertFalse(router2.equals(router));
    URL url3 = new URL("motan", "localhost", 8002, "urlpath3");
    Provider provider3 = new DefaultProvider(null, url3, MessageHandler.class);
    ProviderMessageRouter router3 = protocol.initRequestRouter(url3, provider3);
    assertNotNull(router3);
    assertTrue(router3.equals(router));
    try {
        protocol.initRequestRouter(url, provider);
        assertTrue(false);
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("duplicate yar provider"));
    }
}
Also used : ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) URL(com.weibo.api.motan.rpc.URL) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) Provider(com.weibo.api.motan.rpc.Provider) Test(org.junit.Test)

Example 2 with ProviderMessageRouter

use of com.weibo.api.motan.transport.ProviderMessageRouter in project motan by weibocom.

the class NettyEndpointFactoryTest method testNotShareChannel.

private void testNotShareChannel(boolean isServer) {
    NettyEndpointFactory factory = new NettyEndpointFactory();
    MessageHandler handler = new ProviderMessageRouter();
    URL url = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
    Endpoint endpoint = createEndpoint(url, handler, isServer, factory);
    Assert.assertEquals(endpoint.getUrl().getUri(), url.getUri());
    url = new URL("motan", "localhost", 18081, "com.weibo.api.motan.procotol.example.IHello");
    endpoint = createEndpoint(url, handler, isServer, factory);
    Assert.assertEquals(endpoint.getUrl().getUri(), url.getUri());
    Assert.assertTrue(endpoint != createEndpoint(new URL("motan", "localhost", 18081, "com.weibo.api.motan.procotol.example.IHello"), handler, isServer, factory));
    if (isServer) {
        Assert.assertEquals(factory.getShallServerChannels().size(), 0);
    }
    if (isServer) {
        factory.safeReleaseResource((Server) endpoint, url);
    } else {
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 3);
        factory.safeReleaseResource((Client) endpoint, url);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 2);
    }
}
Also used : HeartbeatClientEndpointManager(com.weibo.api.motan.transport.support.HeartbeatClientEndpointManager) ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter) MessageHandler(com.weibo.api.motan.transport.MessageHandler) Endpoint(com.weibo.api.motan.transport.Endpoint) URL(com.weibo.api.motan.rpc.URL)

Example 3 with ProviderMessageRouter

use of com.weibo.api.motan.transport.ProviderMessageRouter in project motan by weibocom.

the class NettyEndpointFactoryTest method testShareChannel.

private void testShareChannel(boolean isServer) {
    NettyEndpointFactory factory = new NettyEndpointFactory();
    MessageHandler handler = new ProviderMessageRouter();
    URL url1 = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
    url1.addParameter(URLParamType.shareChannel.getName(), "true");
    Endpoint endpoint1 = createEndpoint(url1, handler, isServer, factory);
    Assert.assertEquals(endpoint1.getUrl().getServerPortStr(), url1.getServerPortStr());
    URL url2 = new URL("motan", "localhost", 18081, "com.weibo.api.motan.protocol.example.IHello1");
    url2.addParameter(URLParamType.shareChannel.getName(), "true");
    Endpoint endpoint2 = createEndpoint(url2, handler, isServer, factory);
    Assert.assertEquals(endpoint2.getUrl().getServerPortStr(), url2.getServerPortStr());
    URL url3 = new URL("motan", "localhost", 18081, "com.weibo.api.motan.protocol.example.IHello2");
    url3.addParameter(URLParamType.shareChannel.getName(), "true");
    Endpoint endpoint3 = createEndpoint(url3, handler, isServer, factory);
    if (isServer) {
        Assert.assertTrue(endpoint2 == endpoint3);
    } else {
        Assert.assertTrue(endpoint2 != endpoint3);
    }
    URL url4 = new URL("injvm", "localhost", 18081, "com.weibo.api.motan.protocol.example.IHello3");
    url4.addParameter(URLParamType.shareChannel.getName(), "true");
    Endpoint endpoint4 = null;
    if (isServer) {
        try {
            endpoint4 = createEndpoint(url4, handler, isServer, factory);
            Assert.assertTrue(false);
        } catch (Exception e) {
            Assert.assertTrue(true);
        }
    } else {
        try {
            endpoint4 = createEndpoint(url4, handler, isServer, factory);
            Assert.assertTrue(true);
        } catch (Exception e) {
            Assert.assertTrue(false);
        }
    }
    if (isServer) {
        Assert.assertEquals(factory.getShallServerChannels().size(), 2);
    }
    if (isServer) {
        factory.safeReleaseResource((Server) endpoint1, url1);
        factory.safeReleaseResource((Server) endpoint2, url2);
        factory.safeReleaseResource((Server) endpoint3, url3);
        Assert.assertEquals(factory.getShallServerChannels().size(), 0);
    } else {
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 4);
        factory.safeReleaseResource((Client) endpoint1, url1);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 3);
        factory.safeReleaseResource((Client) endpoint2, url2);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 2);
        factory.safeReleaseResource((Client) endpoint3, url3);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 1);
        factory.safeReleaseResource((Client) endpoint4, url4);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 0);
    }
}
Also used : HeartbeatClientEndpointManager(com.weibo.api.motan.transport.support.HeartbeatClientEndpointManager) ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter) MessageHandler(com.weibo.api.motan.transport.MessageHandler) Endpoint(com.weibo.api.motan.transport.Endpoint) URL(com.weibo.api.motan.rpc.URL)

Example 4 with ProviderMessageRouter

use of com.weibo.api.motan.transport.ProviderMessageRouter in project motan by weibocom.

the class YarRpcProtocol method initRequestRouter.

public ProviderMessageRouter initRequestRouter(URL url, Provider<?> provider) {
    String ipPort = url.getServerPortStr();
    ProviderMessageRouter requestRouter = ipPort2RequestRouter.get(ipPort);
    if (requestRouter == null) {
        ipPort2RequestRouter.putIfAbsent(ipPort, new YarMessageRouter());
        requestRouter = ipPort2RequestRouter.get(ipPort);
    }
    requestRouter.addProvider(provider);
    return requestRouter;
}
Also used : ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter)

Example 5 with ProviderMessageRouter

use of com.weibo.api.motan.transport.ProviderMessageRouter in project motan by weibocom.

the class YarRpcProtocol method unexport.

public void unexport(URL url, Provider<?> provider) {
    String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
    String ipPort = url.getServerPortStr();
    Exporter<?> exporter = (Exporter<?>) exporterMap.remove(protocolKey);
    if (exporter != null) {
        exporter.destroy();
    }
    synchronized (ipPort2RequestRouter) {
        ProviderMessageRouter requestRouter = ipPort2RequestRouter.get(ipPort);
        if (requestRouter != null) {
            requestRouter.removeProvider(provider);
        }
    }
    LoggerUtil.info("yarRpcExporter unexport Success: url={}", url);
}
Also used : ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter) Exporter(com.weibo.api.motan.rpc.Exporter)

Aggregations

ProviderMessageRouter (com.weibo.api.motan.transport.ProviderMessageRouter)5 URL (com.weibo.api.motan.rpc.URL)3 Endpoint (com.weibo.api.motan.transport.Endpoint)2 MessageHandler (com.weibo.api.motan.transport.MessageHandler)2 HeartbeatClientEndpointManager (com.weibo.api.motan.transport.support.HeartbeatClientEndpointManager)2 DefaultProvider (com.weibo.api.motan.rpc.DefaultProvider)1 Exporter (com.weibo.api.motan.rpc.Exporter)1 Provider (com.weibo.api.motan.rpc.Provider)1 Test (org.junit.Test)1