Search in sources :

Example 1 with Request

use of com.weibo.api.motan.rpc.Request in project motan by weibocom.

the class FailoverHaStrategyTest method setUp.

@Before
@Override
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    super.setUp();
    loadBalance = mockery.mock(LoadBalance.class);
    final Referer<IWorld> referer1 = mockery.mock(Referer.class, "ref1");
    final Referer<IWorld> referer2 = mockery.mock(Referer.class, "ref2");
    referers = new ArrayList<Referer<IWorld>>();
    referers.add(referer1);
    referers.add(referer2);
    failoverHaStrategy = new FailoverHaStrategy<IWorld>() {

        @Override
        protected List<Referer<IWorld>> selectReferers(Request request, LoadBalance<IWorld> loadBalance) {
            return referers;
        }
    };
    URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.LOCALHOST, 0, IWorld.class.getName());
    url.addParameter(URLParamType.retries.getName(), String.valueOf(retries));
    failoverHaStrategy.setUrl(url);
}
Also used : IWorld(com.weibo.api.motan.protocol.example.IWorld) LoadBalance(com.weibo.api.motan.cluster.LoadBalance) Referer(com.weibo.api.motan.rpc.Referer) Request(com.weibo.api.motan.rpc.Request) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.weibo.api.motan.rpc.URL) Before(org.junit.Before)

Example 2 with Request

use of com.weibo.api.motan.rpc.Request in project incubator-skywalking by apache.

the class MotanProviderInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getAttachments().get(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.MOTAN);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Request(com.weibo.api.motan.rpc.Request) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 3 with Request

use of com.weibo.api.motan.rpc.Request in project incubator-skywalking by apache.

the class MotanConsumerInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    URL url = (URL) objInst.getSkyWalkingDynamicField();
    Request request = (Request) allArguments[0];
    if (url != null) {
        ContextCarrier contextCarrier = new ContextCarrier();
        String remotePeer = url.getHost() + ":" + url.getPort();
        AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer);
        span.setComponent(ComponentsDefine.MOTAN);
        Tags.URL.set(span, url.getIdentity());
        SpanLayer.asRPCFramework(span);
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            request.setAttachment(next.getHeadKey(), next.getHeadValue());
        }
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Request(com.weibo.api.motan.rpc.Request) URL(com.weibo.api.motan.rpc.URL) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 4 with Request

use of com.weibo.api.motan.rpc.Request in project motan by weibocom.

the class NettyEncoder method encode.

@Override
protected Object encode(ChannelHandlerContext ctx, Channel nettyChannel, Object message) throws Exception {
    byte[] data = encodeMessage(message);
    ChannelBuffer channelBuffer;
    short type = ByteUtil.bytes2short(data, 0);
    if (type == DefaultRpcCodec.MAGIC) {
        channelBuffer = encodeV1(message, data);
    } else if (type == MotanV2Header.MAGIC) {
        channelBuffer = encodeV2(data);
    } else {
        throw new MotanFrameworkException("can not encode message, unknown magic:" + type);
    }
    if (message instanceof Response) {
        ((Response) message).setAttachment(MotanConstants.CONTENT_LENGTH, String.valueOf(channelBuffer.readableBytes()));
    }
    if (message instanceof Request) {
        MotanFrameworkUtil.logEvent((Request) message, MotanConstants.TRACE_CENCODE);
    } else if (message instanceof Response) {
        MotanFrameworkUtil.logEvent((Response) message, MotanConstants.TRACE_SENCODE);
    }
    return channelBuffer;
}
Also used : Response(com.weibo.api.motan.rpc.Response) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Request(com.weibo.api.motan.rpc.Request) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 5 with Request

use of com.weibo.api.motan.rpc.Request in project motan by weibocom.

the class UnSerializableClass method testNettyRequestDecodeException.

/**
 * @throws Exception
 */
@Test
public void testNettyRequestDecodeException() throws Exception {
    NettyServer nettyServer;
    nettyServer = new NettyServer(url, new MessageHandler() {

        @Override
        public Object handle(Channel channel, Object message) {
            Request request = (Request) message;
            DefaultResponse response = new DefaultResponse();
            response.setRequestId(request.getRequestId());
            response.setValue("success");
            return response;
        }
    });
    nettyServer.open();
    NettyClient nettyClient = new NettyClient(url);
    nettyClient.open();
    DefaultRequest request = new DefaultRequest();
    request.setRequestId(RequestIdGenerator.getRequestId());
    request.setInterfaceName(url.getPath());
    request.setMethodName("hello");
    request.setParamtersDesc("void");
    try {
        nettyClient.request(request);
        Assert.assertTrue(false);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("framework decode error"));
    } finally {
        nettyClient.close();
        nettyServer.close();
    }
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MessageHandler(com.weibo.api.motan.transport.MessageHandler) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Channel(com.weibo.api.motan.transport.Channel) Request(com.weibo.api.motan.rpc.Request) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Aggregations

Request (com.weibo.api.motan.rpc.Request)31 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)12 Expectations (org.jmock.Expectations)12 Response (com.weibo.api.motan.rpc.Response)10 IHello (com.weibo.api.motan.protocol.example.IHello)9 URL (com.weibo.api.motan.rpc.URL)9 Test (org.junit.Test)9 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)7 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)6 Referer (com.weibo.api.motan.rpc.Referer)5 HashMap (java.util.HashMap)5 RegistryService (com.weibo.api.motan.registry.RegistryService)4 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 IWorld (com.weibo.api.motan.protocol.example.IWorld)3 Channel (com.weibo.api.motan.transport.Channel)3 MessageHandler (com.weibo.api.motan.transport.MessageHandler)3 YarRequest (com.weibo.yar.YarRequest)3 ArrayList (java.util.ArrayList)3 Serialization (com.weibo.api.motan.codec.Serialization)2 IOException (java.io.IOException)2