当前位置: 首页>>代码示例>>Java>>正文


Java RpcContext类代码示例

本文整理汇总了Java中com.alibaba.dubbo.rpc.RpcContext的典型用法代码示例。如果您正苦于以下问题:Java RpcContext类的具体用法?Java RpcContext怎么用?Java RpcContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RpcContext类属于com.alibaba.dubbo.rpc包,在下文中一共展示了RpcContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribe

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public void subscribe(URL url, NotifyListener listener) {
    if (getUrl().getPort() == 0) {
        URL registryUrl = RpcContext.getContext().getUrl();
        if (registryUrl != null && registryUrl.getPort() > 0
        		&& RegistryService.class.getName().equals(registryUrl.getPath())) {
            super.setUrl(registryUrl);
            super.register(registryUrl);
        }
    }
    String client = RpcContext.getContext().getRemoteAddressString();
    ConcurrentMap<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
    if (clientListeners == null) {
        remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap<URL, Set<NotifyListener>>());
        clientListeners = remoteSubscribed.get(client);
    }
    Set<NotifyListener> listeners = clientListeners.get(url);
    if (listeners == null) {
        clientListeners.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
        listeners = clientListeners.get(url);
    }
    listeners.add(listener);
    super.subscribe(url, listener);
    subscribed(url, listener);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:25,代码来源:SimpleRegistryService.java

示例2: buildParentSpan

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
private Span buildParentSpan(RpcContext carrier, boolean skip,
                             long traceId, long spanId) {
    Map<String, String> attachments = carrier.getAttachments();
    Span.SpanBuilder span = Span.builder().traceId(traceId).spanId(spanId);
    String processId = attachments.get(Span.PROCESS_ID_NAME);
    String parentName = attachments.get(Span.SPAN_NAME_NAME);
    if (StringUtils.hasText(parentName)) {
        span.name(parentName);
    }
    if (StringUtils.hasText(processId)) {
        span.processId(processId);
    }
    if (attachments.get(Span.PARENT_ID_NAME) != null) {
        span.parent(Span
                .hexToId(attachments.get(Span.PARENT_ID_NAME)));
    }
    span.remote(true);
    if (skip) {
        span.exportable(false);
    }
    return span.build();
}
 
开发者ID:threeq,项目名称:dubbo-zipkin,代码行数:23,代码来源:DubboSpanExtractor.java

示例3: testSetContext

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSetContext() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:ContextFilterTest.java

示例4: afterPreCap

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {

    String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);

    Span span = this.spanFactory.getSpanFromContext(url);

    String spanMeta = this.spanFactory.getSpanMeta(span);
    RpcContext.getContext().setAttachment(InvokeChainConstants.PARAM_RPCHEAD_SPANINFO, spanMeta);
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        SlowOperContext slowOperContext = new SlowOperContext();
        // dubbo虽属于rpc,但从其使用方式上属于方法级
        Invocation invocation = (Invocation) args[1];
        slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_PARAMS, parseParams(invocation.getArguments()));

        Object params[] = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap",
                span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:21,代码来源:DubboConsumerAdapter.java

示例5: filter

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public void filter(ClientRequestContext requestContext) throws IOException {
    int size = 0;
    for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) {
        if (entry.getValue().contains(",") || entry.getValue().contains("=")
                || entry.getKey().contains(",") || entry.getKey().contains("=")) {
            throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
        }

        // TODO for now we don't consider the differences of encoding and server limit
        size += entry.getValue().getBytes("UTF-8").length;
        if (size > MAX_HEADER_SIZE) {
            throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " is too big");
        }

        StringBuilder attachments = new StringBuilder();
        attachments.append(entry.getKey());
        attachments.append("=");
        attachments.append(entry.getValue());
        requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments.toString());
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:22,代码来源:RpcContextFilter.java

示例6: testGenericFilter

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} } );
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:MonitorFilterTest.java

示例7: test_Async_Future_Multi

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Test
public void test_Async_Future_Multi() throws Exception {
    initOrResetUrl(true);
    destroyService();
    exportService();
    referService();
    
    int requestId1 = 1;
    Person ret = demoProxy.get(requestId1);
    Assert.assertEquals(null, ret);
    Future<Person> p1Future = RpcContext.getContext().getFuture();
    
    int requestId2 = 1;
    Person ret2 = demoProxy.get(requestId2);
    Assert.assertEquals(null, ret2);
    Future<Person> p2Future = RpcContext.getContext().getFuture();
    
    ret = p1Future.get(1000, TimeUnit.MICROSECONDS);
    ret2 = p2Future.get(1000, TimeUnit.MICROSECONDS);
    Assert.assertEquals(requestId1, ret.getId());
    Assert.assertEquals(requestId2, ret.getId());
    destroyService();
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:24,代码来源:ImplicitCallBackTest.java

示例8: invoke

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
        RpcContext context = RpcContext.getContext(); // 提供方必须在invoke()之前获取context信息
        long start = System.currentTimeMillis(); // 记录起始时间戮
        getConcurrent(invoker, invocation).incrementAndGet(); // 并发计数
        try {
            Result result = invoker.invoke(invocation); // 让调用链往下执行
            collect(invoker, invocation, result, context, start, false);
            return result;
        } catch (RpcException e) {
            collect(invoker, invocation, null, context, start, true);
            throw e;
        } finally {
            getConcurrent(invoker, invocation).decrementAndGet(); // 并发计数
        }
    } else {
        return invoker.invoke(invocation);
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:20,代码来源:MonitorFilter.java

示例9: invoke

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    RpcContext.getContext()
            .setInvoker(invoker)
            .setInvocation(invocation)
            .setLocalAddress(NetUtils.getLocalHost(), 0)
            .setRemoteAddress(invoker.getUrl().getHost(), 
                              invoker.getUrl().getPort());
    if (invocation instanceof RpcInvocation) {
        ((RpcInvocation)invocation).setInvoker(invoker);
    }
    try {
        return invoker.invoke(invocation);
    } finally {
        RpcContext.getContext().clearAttachments();
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:17,代码来源:ConsumerContextFilter.java

示例10: testRetryFailed

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Test()
public void testRetryFailed() {

    resetInvokerToException();

    FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<FailbackClusterInvokerTest>(
                                                                                                                        dic);
    invoker.invoke(invocation);
    Assert.assertNull(RpcContext.getContext().getInvoker());
    invoker.retryFailed();// when retry the invoker which get from failed map already is not the mocked invoker,so
                          // it can be invoke successfully
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:13,代码来源:FailbackClusterInvokerTest.java

示例11: invoke

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (RpcContext.getContext().isConsumerSide()) {
        RpcContext.getContext().setAttachment(CommonConstant.TX_TRANSACTION_GROUP,
                TxTransactionLocal.getInstance().getTxGroupId());
    }
    return invoker.invoke(invocation);
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:9,代码来源:DubboTxTransactionFilter.java

示例12: doInvoke

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public Result doInvoke(Invocation invocation) throws Throwable {
    Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
    if (exporter == null)  {
        throw new RpcException("Service [" + key + "] not found.");
    }
    RpcContext.getContext().setRemoteAddress(NetUtils.LOCALHOST, 0);
    return exporter.getInvoker().invoke(invocation);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:9,代码来源:InjvmInvoker.java

示例13: unregister

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public void unregister(URL url) {
    String client = RpcContext.getContext().getRemoteAddressString();
    Set<URL> urls = remoteRegistered.get(client);
    if (urls != null && urls.size() > 0) {
        urls.remove(url);
    }
    super.unregister(url);
    unregistered(url);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:SimpleRegistryService.java

示例14: reply

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
@Override
public Object reply( ExchangeChannel channel, Object msg ) throws RemotingException {

    if ( msg instanceof Invocation ) {
        Invocation inv = ( Invocation ) msg;
        String serviceName = inv.getAttachments().get(Constants.INTERFACE_KEY);
        String serviceKey = serviceKey( channel.getLocalAddress().getPort(),
                                        serviceName, null, null );
        DubboExporter<?> exporter = (DubboExporter<?>) exporterMap.get( serviceKey );
        if (exporter == null) {
            throw new RemotingException(channel,
                                        "Not found exported service: "
                                                + serviceKey
                                                + " in "
                                                + exporterMap.keySet()
                                                + ", may be version or group mismatch "
                                                + ", channel: consumer: "
                                                + channel.getRemoteAddress()
                                                + " --> provider: "
                                                + channel.getLocalAddress()
                                                + ", message:"+ msg);
        }

        RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
        return exporter.getInvoker().invoke( inv );

    }

    throw new RemotingException(channel,
                                "Unsupported request: "
                                        + (msg.getClass().getName() + ": " + msg)
                                        + ", channel: consumer: "
                                        + channel.getRemoteAddress()
                                        + " --> provider: "
                                        + channel.getLocalAddress());
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:37,代码来源:ThriftProtocol.java

示例15: handle

import com.alibaba.dubbo.rpc.RpcContext; //导入依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (! request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:16,代码来源:HttpProtocol.java


注:本文中的com.alibaba.dubbo.rpc.RpcContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。