Search in sources :

Example 1 with Client

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

the class HeartbeatClientEndpointManager method addEndpoint.

@Override
public void addEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof Client)) {
        throw new MotanFrameworkException("HeartbeatClientEndpointManager addEndpoint Error: class not support " + endpoint.getClass());
    }
    Client client = (Client) endpoint;
    URL url = endpoint.getUrl();
    String heartbeatFactoryName = url.getParameter(URLParamType.heartbeatFactory.getName(), URLParamType.heartbeatFactory.getValue());
    HeartbeatFactory heartbeatFactory = ExtensionLoader.getExtensionLoader(HeartbeatFactory.class).getExtension(heartbeatFactoryName);
    if (heartbeatFactory == null) {
        throw new MotanFrameworkException("HeartbeatFactory not exist: " + heartbeatFactoryName);
    }
    endpoints.put(client, heartbeatFactory);
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) HeartbeatFactory(com.weibo.api.motan.transport.HeartbeatFactory) Client(com.weibo.api.motan.transport.Client) URL(com.weibo.api.motan.rpc.URL)

Example 2 with Client

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

the class BaseTest method before.

@Before
public void before() {
    mockery = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    final Server mockServer = mockery.mock(Server.class);
    final Client mockClient = mockery.mock(Client.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockClient).open();
            will(returnValue(true));
            allowing(mockClient).close();
            will(returnValue(null));
            allowing(mockClient).isAvailable();
            will(returnValue(true));
            allowing(mockServer).open();
            will(returnValue(true));
            allowing(mockServer).close();
            will(returnValue(null));
            allowing(mockServer).isAvailable();
            will(returnValue(true));
        }
    });
    ExtensionLoader loader = ExtensionLoader.getExtensionLoader(EndpointFactory.class);
    endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint");
    if (endpointFactory == null) {
        loader.addExtensionClass(MockEndpointFactory.class);
        endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint");
    }
    loader = ExtensionLoader.getExtensionLoader(RegistryFactory.class);
    MockRegistryFactory registryFactory = (MockRegistryFactory) loader.getExtension("mockRegistry");
    if (registryFactory == null) {
        loader.addExtensionClass(MockRegistryFactory.class);
    }
    endpointFactory.setClient(mockClient);
    endpointFactory.setServer(mockServer);
    cp = new ClassPathXmlApplicationContext("classpath:schemaTestContext.xml");
}
Also used : Expectations(org.jmock.Expectations) RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Server(com.weibo.api.motan.transport.Server) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Client(com.weibo.api.motan.transport.Client) ExtensionLoader(com.weibo.api.motan.core.extension.ExtensionLoader) Before(org.junit.Before)

Example 3 with Client

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

the class AbstractEndpointFactory method createClient.

private Client createClient(URL url, EndpointManager endpointManager) {
    Client client = innerCreateClient(url);
    endpointManager.addEndpoint(client);
    return client;
}
Also used : Client(com.weibo.api.motan.transport.Client)

Aggregations

Client (com.weibo.api.motan.transport.Client)3 ExtensionLoader (com.weibo.api.motan.core.extension.ExtensionLoader)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 RegistryFactory (com.weibo.api.motan.registry.RegistryFactory)1 URL (com.weibo.api.motan.rpc.URL)1 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)1 Server (com.weibo.api.motan.transport.Server)1 Expectations (org.jmock.Expectations)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 Before (org.junit.Before)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1