本文整理汇总了Java中com.alibaba.dubbo.rpc.RpcInvocation.setAttachment方法的典型用法代码示例。如果您正苦于以下问题:Java RpcInvocation.setAttachment方法的具体用法?Java RpcInvocation.setAttachment怎么用?Java RpcInvocation.setAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.rpc.RpcInvocation
的用法示例。
在下文中一共展示了RpcInvocation.setAttachment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeInvocationArgument
import com.alibaba.dubbo.rpc.RpcInvocation; //导入方法依赖的package包/类
public static Object encodeInvocationArgument(Channel channel, RpcInvocation inv, int paraIndex) throws IOException{
//encode时可直接获取url
URL url = inv.getInvoker() == null ? null : inv.getInvoker().getUrl();
byte callbackstatus = isCallBack(url, inv.getMethodName(), paraIndex);
Object[] args = inv.getArguments();
Class<?>[] pts = inv.getParameterTypes();
switch (callbackstatus) {
case CallbackServiceCodec.CALLBACK_NONE:
return args[paraIndex];
case CallbackServiceCodec.CALLBACK_CREATE:
inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex , exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], true));
return null;
case CallbackServiceCodec.CALLBACK_DESTROY:
inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex, exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], false));
return null;
default:
return args[paraIndex];
}
}
示例2: testNotify_MockProviderOnly
import com.alibaba.dubbo.rpc.RpcInvocation; //导入方法依赖的package包/类
/**
* 测试mock provider下发
*/
@Test
public void testNotify_MockProviderOnly() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL.setProtocol(Constants.MOCK_PROTOCOL));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
RpcInvocation mockinvocation = new RpcInvocation();
mockinvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
invokers = registryDirectory.list(mockinvocation);
Assert.assertEquals(1, invokers.size());
}
示例3: testNotify_MockProviderOnly
import com.alibaba.dubbo.rpc.RpcInvocation; //导入方法依赖的package包/类
/**
* 测试mock provider下发
*/
@Test
public void testNotify_MockProviderOnly() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL.setProtocol(Constants.MOCK_PROTOCOL));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
RpcInvocation mockinvocation = new RpcInvocation();
mockinvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
invokers = registryDirectory.list(mockinvocation);
Assert.assertEquals(1, invokers.size());
}
示例4: createInvocation
import com.alibaba.dubbo.rpc.RpcInvocation; //导入方法依赖的package包/类
private Invocation createInvocation(Channel channel, URL url, String methodKey) {
String method = url.getParameter(methodKey);
if (method == null || method.length() == 0) {
return null;
}
RpcInvocation invocation = new RpcInvocation(method, new Class<?>[0], new Object[0]);
invocation.setAttachment(Constants.PATH_KEY, url.getPath());
invocation.setAttachment(Constants.GROUP_KEY, url.getParameter(Constants.GROUP_KEY));
invocation.setAttachment(Constants.INTERFACE_KEY, url.getParameter(Constants.INTERFACE_KEY));
invocation.setAttachment(Constants.VERSION_KEY, url.getParameter(Constants.VERSION_KEY));
if (url.getParameter(Constants.STUB_EVENT_KEY, false)){
invocation.setAttachment(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString());
}
return invocation;
}
示例5: createRequest
import com.alibaba.dubbo.rpc.RpcInvocation; //导入方法依赖的package包/类
private Request createRequest() {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName( "echoString" );
invocation.setArguments( new Object[]{ "Hello, World!" } );
invocation.setParameterTypes( new Class<?>[]{ String.class } );
invocation.setAttachment( Constants.INTERFACE_KEY, Demo.Iface.class.getName() );
Request request = new Request( 1L );
request.setData( invocation );
return request;
}