Java Code Examples for com.alibaba.dubbo.rpc.Invocation#getAttachments()

The following examples show how to use com.alibaba.dubbo.rpc.Invocation#getAttachments() . 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 void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request,
		TransactionResponseImpl response) {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

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

	transactionInterceptor.beforeSendRequest(request);
	if (request.getTransactionContext() != null) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		HessianOutput output = new HessianOutput(baos);
		try {
			output.writeObject(request.getTransactionContext());
		} catch (IOException ex) {
			logger.error("Error occurred in remote call!", ex);
			throw new RemotingException(ex.getMessage());
		}

		String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray());
		attachments.put(TransactionContext.class.getName(), transactionContextContent);
	}
}
 
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: 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 4
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request,
		TransactionResponseImpl response) {
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant();

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

	transactionInterceptor.beforeSendRequest(request);
	if (request.getTransactionContext() != null) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		HessianOutput output = new HessianOutput(baos);
		try {
			output.writeObject(request.getTransactionContext());
		} catch (IOException ex) {
			logger.error("Error occurred in remote call!", ex);
			throw new RpcException("Error occurred in remote call!", ex);
		}
		String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray());
		attachments.put(TransactionContext.class.getName(), transactionContextContent);
	}

}
 
Example 5
Source File: ContextFilter.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    Map<String, String> attachments = invocation.getAttachments();
    if (attachments != null) {
        attachments = new HashMap<>(attachments);
        attachments.remove(Constants.PATH_KEY);
        attachments.remove(Constants.GROUP_KEY);
        attachments.remove(Constants.VERSION_KEY);
        attachments.remove(Constants.DUBBO_VERSION_KEY);
        attachments.remove(Constants.TOKEN_KEY);
        attachments.remove(Constants.TIMEOUT_KEY);
    }
    RpcContext.getContext()
            .setInvoker(invoker)
            .setInvocation(invocation)
            .setAttachments(attachments)
            .setLocalAddress(invoker.getUrl().getHost(), 
                             invoker.getUrl().getPort());
    if (invocation instanceof RpcInvocation) {
        ((RpcInvocation)invocation).setInvoker(invoker);
    }
    try {
        return invoker.invoke(invocation);
    } finally {
        RpcContext.removeContext();
    }
}
 
Example 6
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request,
		TransactionResponseImpl response) {
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();

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

	transactionInterceptor.beforeSendRequest(request);
	if (request.getTransactionContext() != null) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		HessianOutput output = new HessianOutput(baos);
		try {
			output.writeObject(request.getTransactionContext());
		} catch (IOException ex) {
			logger.error("Error occurred in remote call!", ex);
			throw new RemotingException(ex.getMessage());
		}

		String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray());
		attachments.put(TransactionContext.class.getName(), transactionContextContent);
	}
}
 
Example 7
Source File: MockInvokersSelector.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
		URL url, final Invocation invocation) throws RpcException {
	if (invocation.getAttachments() == null) {
		return getNormalInvokers(invokers);
	} else {
		String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
		if (value == null) 
			return getNormalInvokers(invokers);
		else if (Boolean.TRUE.toString().equalsIgnoreCase(value)){
			return getMockedInvokers(invokers);
		} 
	}
	return invokers;
}
 
Example 8
Source File: MockInvokersSelector.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
		URL url, final Invocation invocation) throws RpcException {
	if (invocation.getAttachments() == null) {
		return getNormalInvokers(invokers);
	} else {
		String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
		if (value == null) 
			return getNormalInvokers(invokers);
		else if (Boolean.TRUE.toString().equalsIgnoreCase(value)){
			return getMockedInvokers(invokers);
		} 
	}
	return invokers;
}
 
Example 9
Source File: ContextFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // modified by lishen
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // modified by lishen
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation)invocation).setInvoker(invoker);
        }
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
 
Example 10
Source File: TokenFilter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 11
Source File: MockInvokersSelector.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
		URL url, final Invocation invocation) throws RpcException {
	if (invocation.getAttachments() == null) {
		return getNormalInvokers(invokers);
	} else {
		String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
		if (value == null) 
			return getNormalInvokers(invokers);
		else if (Boolean.TRUE.toString().equalsIgnoreCase(value)){
			return getMockedInvokers(invokers);
		} 
	}
	return invokers;
}
 
Example 12
Source File: TokenFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 13
Source File: ContextFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // modified by lishen
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // modified by lishen
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation)invocation).setInvoker(invoker);
        }
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
 
Example 14
Source File: MockInvokersSelector.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
                                  URL url, final Invocation invocation) throws RpcException {
    if (invocation.getAttachments() == null) {
        return getNormalInvokers(invokers);
    } else {
        String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
        if (value == null)
            return getNormalInvokers(invokers);
        else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
            return getMockedInvokers(invokers);
        }
    }
    return invokers;
}
 
Example 15
Source File: ContextFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // modified by lishen
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // modified by lishen
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation)invocation).setInvoker(invoker);
        }
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
 
Example 16
Source File: ContextFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // modified by lishen
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // modified by lishen
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation)invocation).setInvoker(invoker);
        }
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
 
Example 17
Source File: TokenFilter.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation inv)
        throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
        String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
        if (!token.equals(remoteToken)) {
            throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider " + RpcContext.getContext().getLocalHost());
        }
    }
    return invoker.invoke(inv);
}
 
Example 18
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 19
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 20
Source File: ContextFilter.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
            attachments.remove(Constants.ASYNC_KEY);// Remove async property to avoid being passed to the following invoke chain.
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // merged from dubbox
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // mreged from dubbox
        // we may already added some attachments into RpcContext before this filter (e.g. in rest protocol)
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation) invocation).setInvoker(invoker);
        }
        try {
//            invoker执行
            RpcResult result = (RpcResult) invoker.invoke(invocation);
            // pass attachments to result
            result.addAttachments(RpcContext.getServerContext().getAttachments());
            return result;
        } finally {
//            清除上下文
            RpcContext.removeContext();
            RpcContext.getServerContext().clearAttachments();
        }
    }