Search in sources :

Example 11 with UnitInstance

use of info.xiancloud.core.distribution.service_discovery.UnitInstance in project xian by happyyangyuan.

the class CachedGlobalHttpSessionCountMonitor method execute0.

@Override
public Object execute0() {
    int totalSessionCount = 0;
    try {
        for (UnitInstance clientInfo : UnitRouter.singleton.allInstances(Unit.fullName("httpServer", "cachedLocalHttpSessionMonitor"))) {
            int localSessionCount;
            UnitRequest request = UnitRequest.create("httpServer", "cachedLocalHttpSessionMonitor");
            request.getContext().setDestinationNodeId(clientInfo.getNodeId());
            List<Integer> counts = SyncXian.call(request, 5 * 1000).dataToTypedList(Integer.class);
            totalSessionCount = MathUtil.sum(counts);
        }
    } catch (UnitOfflineException | UnitUndefinedException e) {
        LOG.error(e);
        totalSessionCount = -1;
    }
    LOG.info("当前缓存的session总数量为:" + totalSessionCount);
    return UnitResponse.success(totalSessionCount);
}
Also used : UnitOfflineException(info.xiancloud.core.distribution.exception.UnitOfflineException) UnitRequest(info.xiancloud.core.message.UnitRequest) UnitInstance(info.xiancloud.core.distribution.service_discovery.UnitInstance) UnitUndefinedException(info.xiancloud.core.distribution.exception.UnitUndefinedException)

Example 12 with UnitInstance

use of info.xiancloud.core.distribution.service_discovery.UnitInstance in project xian by happyyangyuan.

the class UnitUnregistrationBridge method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    UnitProxy unitProxy = msg.get("unit", UnitProxy.class);
    NodeStatus nodeStatus = msg.get("nodeStatus", NodeStatus.class);
    UnitInstance unitInstance = UnitRegistrationBridge.unitInstance(unitProxy, nodeStatus);
    try {
        UnitDiscovery.singleton.unregister(unitInstance);
        return UnitResponse.success();
    } catch (Exception e) {
        LOG.error(e);
        return UnitResponse.failure(e, "unit un registration failure.");
    }
}
Also used : UnitInstance(info.xiancloud.core.distribution.service_discovery.UnitInstance) UnitProxy(info.xiancloud.core.distribution.UnitProxy) NodeStatus(info.xiancloud.core.distribution.NodeStatus)

Aggregations

UnitInstance (info.xiancloud.core.distribution.service_discovery.UnitInstance)12 UnitOfflineException (info.xiancloud.core.distribution.exception.UnitOfflineException)6 UnitUndefinedException (info.xiancloud.core.distribution.exception.UnitUndefinedException)3 UnitRequest (info.xiancloud.core.message.UnitRequest)3 ArrayList (java.util.ArrayList)3 NotifyHandler (info.xiancloud.core.NotifyHandler)2 NodeStatus (info.xiancloud.core.distribution.NodeStatus)2 UnitProxy (info.xiancloud.core.distribution.UnitProxy)2 UnitInstanceIdBean (info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean)2 UnitResponse (info.xiancloud.core.message.UnitResponse)2 RoutedLocalAsyncSender (info.xiancloud.core.message.sender.local.RoutedLocalAsyncSender)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Unit (info.xiancloud.core.Unit)1 UnitMeta (info.xiancloud.core.UnitMeta)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1