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;
}
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) {
}
}));
}
}
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();
}
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;
}
Aggregations