Search in sources :

Example 1 with ForwardInfo

use of com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo in project x-pipe by ctripcorp.

the class MultiMetaServer method copy.

private Object[] copy(Object[] rawArgs) {
    Object[] array = Arrays.copyOf(rawArgs, rawArgs.length);
    for (int i = 0; i < array.length; i++) {
        if (array[i] instanceof ForwardInfo) {
            ForwardInfo rawForwardInfo = (ForwardInfo) array[i];
            array[i] = rawForwardInfo.clone();
        }
    }
    return array;
}
Also used : ForwardInfo(com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo)

Example 2 with ForwardInfo

use of com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo in project x-pipe by ctripcorp.

the class MultiMetaServerTest method testMultiProxy.

@Test
public void testMultiProxy() {
    int serversCount = 10;
    List<MetaServer> servers = new LinkedList<>();
    for (int i = 0; i < serversCount - 1; i++) {
        servers.add(mock(MetaServer.class));
    }
    MetaServer metaServer = MultiMetaServer.newProxy(mock(MetaServer.class), servers);
    final ForwardInfo forwardInfo = new ForwardInfo();
    metaServer.clusterDeleted(getClusterId(), forwardInfo);
    for (MetaServer mockServer : servers) {
        verify(mockServer).clusterDeleted(eq(getClusterId()), argThat(new BaseMatcher<ForwardInfo>() {

            @Override
            public boolean matches(Object item) {
                // should be cloned
                if (item == forwardInfo) {
                    return false;
                }
                return true;
            }

            @Override
            public void describeTo(Description description) {
            }
        }));
    }
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) MetaServer(com.ctrip.xpipe.redis.meta.server.MetaServer) ForwardInfo(com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 3 with ForwardInfo

use of com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo in project x-pipe by ctripcorp.

the class DispatchMoving method tryMovingDispatch.

@Around("pointcutMovingMethod() && args(clusterId,..,forwardInfo)")
public Object tryMovingDispatch(ProceedingJoinPoint joinpoint, String clusterId, ForwardInfo forwardInfo) throws Throwable {
    String targetMethodName = joinpoint.getSignature().getName();
    logger.info("[tryMovingDispatch]{}, {}", targetMethodName, clusterId);
    if (forwardInfo != null && forwardInfo.getType() == ForwardType.MOVING) {
        logger.info("[tryMovingDispatch][isMoving][self process]{}, {}", targetMethodName, clusterId);
        return joinpoint.proceed();
    }
    MetaServer exportServer = exportServer(clusterId);
    if (exportServer == currentClusterServer) {
        throw new IllegalStateException("export server should not be current " + exportServer);
    }
    if (exportServer != null) {
        Object[] args = joinpoint.getArgs();
        if (forwardInfo == null) {
            forwardInfo = new ForwardInfo();
            replace(args, forwardInfo);
        }
        forwardInfo.setType(ForwardType.MOVING);
        Method method = ObjectUtils.getMethod(targetMethodName, MetaServer.class);
        if (method == null) {
            // impossible to happen
            throw new IllegalStateException("can not find method " + targetMethodName);
        }
        return method.invoke(exportServer, args);
    }
    return joinpoint.proceed();
}
Also used : MetaServer(com.ctrip.xpipe.redis.meta.server.MetaServer) Method(java.lang.reflect.Method) ForwardInfo(com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo) Around(org.aspectj.lang.annotation.Around)

Example 4 with ForwardInfo

use of com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo in project x-pipe by ctripcorp.

the class RemoteMetaServer method checkCircularAndGetHttpHeaders.

private HttpHeaders checkCircularAndGetHttpHeaders(ForwardInfo forwardInfo, ForwardType forwardType) {
    checkCircular(forwardInfo);
    if (forwardInfo == null) {
        forwardInfo = new ForwardInfo(forwardType);
    } else {
        forwardInfo.setType(forwardType);
    }
    forwardInfo.addForwardServers(getCurrentServerId());
    HttpHeaders headers = new HttpHeaders();
    headers.add(MetaServerService.HTTP_HEADER_FOWRARD, Codec.DEFAULT.encode(forwardInfo));
    return headers;
}
Also used : ForwardInfo(com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo)

Aggregations

ForwardInfo (com.ctrip.xpipe.redis.meta.server.rest.ForwardInfo)4 MetaServer (com.ctrip.xpipe.redis.meta.server.MetaServer)2 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 Around (org.aspectj.lang.annotation.Around)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1 Test (org.junit.Test)1