Java Code Examples for com.alibaba.dubbo.rpc.RpcResult#getValue()

The following examples show how to use com.alibaba.dubbo.rpc.RpcResult#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompensablePrimaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Result convertResultForProvider(RpcResult result, String propagatedBy, boolean attachRequired) {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Object value = result.getValue();

	CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult();
	wrapped.setValue(value);
	if (attachRequired) {
		wrapped.setVariable(Propagation.class.getName(), propagatedBy);
		wrapped.setVariable(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
	}

	result.setException(null);
	result.setValue(wrapped);

	return result;
}
 
Example 2
Source File: CompensablePrimaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
	RpcResult result = (RpcResult) invoker.invoke(invocation);
	Object value = result.getValue();
	if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
		CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}

		// String propagatedBy = (String) wrapped.getVariable(RemoteCoordinator.class.getName());
		// String identifier = compensableCoordinator.getIdentifier();
	}
	return result;
}
 
Example 3
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Result convertResultForProvider(RpcResult result, String propagatedBy, boolean attachRequired) {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Object value = result.getValue();

	CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult();
	wrapped.setValue(value);
	if (attachRequired) {
		wrapped.setVariable(Propagation.class.getName(), propagatedBy);
		wrapped.setVariable(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
	}

	result.setException(null);
	result.setValue(wrapped);

	return result;
}
 
Example 4
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
	RpcResult result = (RpcResult) invoker.invoke(invocation);
	Object value = result.getValue();
	if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
		CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}
	}
	return result;
}
 
Example 5
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Result convertResultForProvider(RpcResult result, String propagatedBy, boolean attachRequired) {
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant();

	Object value = result.getValue();

	InvocationResult wrapped = new InvocationResult();
	wrapped.setValue(value);
	if (attachRequired) {
		wrapped.setVariable(Propagation.class.getName(), propagatedBy);
		wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
	}

	result.setException(null);
	result.setValue(wrapped);

	return result;
}
 
Example 6
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Result consumerInvokeForJTA(Invoker<?> invoker, Invocation invocation) throws RpcException {
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
	RpcResult result = (RpcResult) invoker.invoke(invocation);
	Object value = result.getValue();
	if (InvocationResult.class.isInstance(value)) {
		InvocationResult wrapped = (InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}

	} // end-if (InvocationResult.class.isInstance(value))

	return result;
}
 
Example 7
Source File: CompensablePrimaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Result consumerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());

	RpcResult result = (RpcResult) invoker.invoke(invocation);

	Object value = result.getValue();
	if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
		CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}

		String instanceId = StringUtils.trimToEmpty(String.valueOf(wrapped.getVariable(RemoteCoordinator.class.getName())));

		this.registerRemoteParticipantIfNecessary(instanceId);

		String interfaceClazz = RpcContext.getContext().getUrl().getServiceInterface();
		boolean participantFlag = TransactionParticipant.class.getName().equals(interfaceClazz);
		boolean xaResourceFlag = XAResource.class.getName().equals(interfaceClazz);
		boolean coordinatorFlag = RemoteCoordinator.class.getName().equals(interfaceClazz);
		boolean resultInitRequired = (participantFlag || xaResourceFlag || coordinatorFlag) && result.getValue() == null;
		if (resultInitRequired) {
			if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) {
				result.setValue(instanceId);
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) {
				result.setValue(CommonUtils.getApplication(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) {
				result.setValue(CommonUtils.getRemoteAddr(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) {
				result.setValue(CommonUtils.getRemoteNode(instanceId));
			}
		} // end-if (resultInitRequired)

	} // end-if (CompensableServiceFilter.InvocationResult.class.isInstance(value))

	return result;
}
 
Example 8
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Result consumerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());

	RpcResult result = (RpcResult) invoker.invoke(invocation);

	Object value = result.getValue();
	if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
		CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}

		String instanceId = StringUtils.trimToEmpty(String.valueOf(wrapped.getVariable(RemoteCoordinator.class.getName())));

		this.registerRemoteParticipantIfNecessary(instanceId);

		String interfaceClazz = RpcContext.getContext().getUrl().getServiceInterface();
		boolean participantFlag = TransactionParticipant.class.getName().equals(interfaceClazz);
		boolean xaResourceFlag = XAResource.class.getName().equals(interfaceClazz);
		boolean coordinatorFlag = RemoteCoordinator.class.getName().equals(interfaceClazz);
		boolean resultInitRequired = (participantFlag || xaResourceFlag || coordinatorFlag) && result.getValue() == null;
		if (resultInitRequired) {
			if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) {
				result.setValue(instanceId);
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) {
				result.setValue(CommonUtils.getApplication(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) {
				result.setValue(CommonUtils.getRemoteAddr(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) {
				result.setValue(CommonUtils.getRemoteNode(instanceId));
			}
		} // end-if (resultInitRequired)

	} // end-if (CompensableServiceFilter.InvocationResult.class.isInstance(value))

	return result;
}
 
Example 9
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Result consumerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException {
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());

	RpcResult result = (RpcResult) invoker.invoke(invocation);

	Object value = result.getValue();
	if (InvocationResult.class.isInstance(value)) {
		InvocationResult wrapped = (InvocationResult) value;
		result.setValue(null);
		result.setException(null);

		if (wrapped.isFailure()) {
			result.setException(wrapped.getError());
		} else {
			result.setValue(wrapped.getValue());
		}

		String instanceId = StringUtils.trimToEmpty(String.valueOf(wrapped.getVariable(RemoteCoordinator.class.getName())));

		this.registerRemoteParticipantIfNecessary(instanceId);

		String interfaceClazz = RpcContext.getContext().getUrl().getServiceInterface();
		boolean participantFlag = TransactionParticipant.class.getName().equals(interfaceClazz);
		boolean xaResourceFlag = XAResource.class.getName().equals(interfaceClazz);
		boolean coordinatorFlag = RemoteCoordinator.class.getName().equals(interfaceClazz);
		boolean resultInitRequired = (participantFlag || xaResourceFlag || coordinatorFlag) && result.getValue() == null;
		if (resultInitRequired) {
			if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) {
				result.setValue(instanceId);
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) {
				result.setValue(CommonUtils.getApplication(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) {
				result.setValue(CommonUtils.getRemoteAddr(instanceId));
			} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) {
				result.setValue(CommonUtils.getRemoteNode(instanceId));
			}
		} // end-if (resultInitRequired)

	} // end-if (InvocationResult.class.isInstance(value))

	return result;
}