当前位置: 首页>>代码示例>>Java>>正文


Java ActorContext类代码示例

本文整理汇总了Java中akka.actor.ActorContext的典型用法代码示例。如果您正苦于以下问题:Java ActorContext类的具体用法?Java ActorContext怎么用?Java ActorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ActorContext类属于akka.actor包,在下文中一共展示了ActorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RaftActorContextImpl

import akka.actor.ActorContext; //导入依赖的package包/类
public RaftActorContextImpl(ActorRef actor, ActorContext context, String id,
        @Nonnull ElectionTerm termInformation, long commitIndex, long lastApplied,
        @Nonnull Map<String, String> peerAddresses,
        @Nonnull ConfigParams configParams, @Nonnull DataPersistenceProvider persistenceProvider,
        @Nonnull Consumer<ApplyState> applyStateConsumer, @Nonnull Logger logger) {
    this.actor = actor;
    this.context = context;
    this.id = id;
    this.termInformation = Preconditions.checkNotNull(termInformation);
    this.commitIndex = commitIndex;
    this.lastApplied = lastApplied;
    this.configParams = Preconditions.checkNotNull(configParams);
    this.persistenceProvider = Preconditions.checkNotNull(persistenceProvider);
    this.log = Preconditions.checkNotNull(logger);
    this.applyStateConsumer = Preconditions.checkNotNull(applyStateConsumer);

    fileBackedOutputStreamFactory = new FileBackedOutputStreamFactory(
            configParams.getFileBackedStreamingThreshold(), configParams.getTempFileDirectory());

    for (Map.Entry<String, String> e: Preconditions.checkNotNull(peerAddresses).entrySet()) {
        peerInfoMap.put(e.getKey(), new PeerInfo(e.getKey(), e.getValue(), VotingState.VOTING));
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:RaftActorContextImpl.java

示例2: onUpdate

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void onUpdate(ActorContext context) throws Exception {
  PluginMetaData oldPluginMd = pluginMd;
  pluginMd = systemContext.getPluginService().findPluginById(entityId);
  boolean requiresRestart = false;
  logger.info("[{}] Plugin configuration was updated from {} to {}.", entityId, oldPluginMd, pluginMd);
  if (!oldPluginMd.getClazz().equals(pluginMd.getClazz())) {
    logger.info("[{}] Plugin requires restart due to clazz change from {} to {}.", entityId, oldPluginMd.getClazz(),
        pluginMd.getClazz());
    requiresRestart = true;
  } else if (!oldPluginMd.getConfiguration().equals(pluginMd.getConfiguration())) {
    logger.info("[{}] Plugin requires restart due to configuration change from {} to {}.", entityId,
        oldPluginMd.getConfiguration(), pluginMd.getConfiguration());
    requiresRestart = true;
  }
  if (requiresRestart) {
    this.state = ComponentLifecycleState.SUSPENDED;
    if (pluginImpl != null) {
      pluginImpl.stop(trustedCtx);
    }
    start();
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:PluginActorMessageProcessor.java

示例3: sendPendingRequests

import akka.actor.ActorContext; //导入依赖的package包/类
private void sendPendingRequests(ActorContext context, SessionId sessionId, SessionType type,
    Optional<ServerAddress> server) {
  if (!rpcPendingMap.isEmpty()) {
    logger.debug("[{}] Pushing {} pending RPC messages to new async session [{}]", deviceId, rpcPendingMap.size(),
        sessionId);
    if (type == SessionType.SYNC) {
      logger.debug("[{}] Cleanup sync rpc session [{}]", deviceId, sessionId);
      rpcSubscriptions.remove(sessionId);
    }
  } else {
    logger.debug("[{}] No pending RPC messages for new async session [{}]", deviceId, sessionId);
  }
  Set<UUID> sentOneWayIds = new HashSet<>();
  if (type == SessionType.ASYNC) {
    rpcPendingMap.entrySet().forEach(processPendingRpc(context, sessionId, server, sentOneWayIds));
  } else {
    rpcPendingMap.entrySet().stream().findFirst()
        .ifPresent(processPendingRpc(context, sessionId, server, sentOneWayIds));
  }

  sentOneWayIds.forEach(rpcPendingMap::remove);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:23,代码来源:DeviceActorMessageProcessor.java

示例4: processPendingRpc

import akka.actor.ActorContext; //导入依赖的package包/类
private Consumer<Map.Entry<Integer, ToDeviceRpcRequestMetadata>> processPendingRpc(ActorContext context,
    SessionId sessionId, Optional<ServerAddress> server, Set<UUID> sentOneWayIds) {
  return entry -> {
    ToDeviceRpcRequest request = entry.getValue().getMsg().getMsg();
    ToDeviceRpcRequestBody body = request.getBody();
    if (request.isOneway()) {
      sentOneWayIds.add(request.getId());
      ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(entry.getValue().getMsg(),
          (String) null);
      context.parent().tell(responsePluginMsg, ActorRef.noSender());
    }
    ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg(entry.getKey(), body.getMethod(), body.getParams());
    ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(rpcRequest, sessionId);
    sendMsgToSessionActor(response, server);
  };
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:17,代码来源:DeviceActorMessageProcessor.java

示例5: processSubscriptionCommands

import akka.actor.ActorContext; //导入依赖的package包/类
private void processSubscriptionCommands(ActorContext context, ToDeviceActorMsg msg) {
  SessionId sessionId = msg.getSessionId();
  SessionType sessionType = msg.getSessionType();
  FromDeviceMsg inMsg = msg.getPayload();
  if (inMsg.getMsgType() == MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) {
    logger.debug("[{}] Registering attributes subscription for session [{}]", deviceId, sessionId);
    attributeSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress()));
  } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST) {
    logger.debug("[{}] Canceling attributes subscription for session [{}]", deviceId, sessionId);
    attributeSubscriptions.remove(sessionId);
  } else if (inMsg.getMsgType() == MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST) {
    logger.debug("[{}] Registering rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType);
    rpcSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress()));
    sendPendingRequests(context, sessionId, sessionType, msg.getServerAddress());
  } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST) {
    logger.debug("[{}] Canceling rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType);
    rpcSubscriptions.remove(sessionId);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:20,代码来源:DeviceActorMessageProcessor.java

示例6: update

import akka.actor.ActorContext; //导入依赖的package包/类
public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
  RuleMetaData rule;
  if (event != ComponentLifecycleEvent.DELETED) {
    rule = systemContext.getRuleService().findRuleById(ruleId);
  } else {
    rule = ruleMap.keySet().stream().filter(r -> r.getId().equals(ruleId))
        .peek(r -> r.setState(ComponentLifecycleState.SUSPENDED)).findFirst().orElse(null);
    if (rule != null) {
      ruleMap.remove(rule);
      ruleActors.remove(ruleId);
    }
  }
  if (rule != null) {
    RuleActorMetaData actorMd = ruleMap.get(rule);
    if (actorMd == null) {
      ActorRef ref = getOrCreateRuleActor(context, rule.getId());
      actorMd = RuleActorMetaData.systemRule(rule.getId(), rule.getWeight(), ref);
      ruleMap.put(rule, actorMd);
    }
    refreshRuleChain();
    return Optional.of(actorMd.getActorRef());
  } else {
    log.warn("[{}] Can't process unknown rule!", ruleId);
    return Optional.empty();
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:27,代码来源:RuleManager.java

示例7: processToDeviceMsg

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void processToDeviceMsg(ActorContext context, ToDeviceMsg msg) {
  try {
    if (msg.getMsgType() != MsgType.SESSION_CLOSE) {
      switch (msg.getMsgType()) {
      case STATUS_CODE_RESPONSE:
      case GET_ATTRIBUTES_RESPONSE:
        ResponseMsg responseMsg = (ResponseMsg) msg;
        if (responseMsg.getRequestId() >= 0) {
          logger.debug("[{}] Pending request processed: {}", responseMsg.getRequestId(), responseMsg);
          pendingMap.remove(responseMsg.getRequestId());
        }
        break;
      }
      sessionCtx.onMsg(new BasicSessionActorToAdaptorMsg(this.sessionCtx, msg));
    } else {
      sessionCtx.onMsg(org.iotp.analytics.ruleengine.common.msg.session.ctrl.SessionCloseMsg
          .onCredentialsRevoked(sessionCtx.getSessionId()));
    }
  } catch (SessionException e) {
    logger.warning("Failed to push session response msg", e);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:ASyncMsgProcessor.java

示例8: processToAssetMsg

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void processToAssetMsg(ActorContext context, ToDeviceMsg msg) {
  try {
    if (msg.getMsgType() != MsgType.SESSION_CLOSE) {
      switch (msg.getMsgType()) {
      case STATUS_CODE_RESPONSE:
      case GET_ATTRIBUTES_RESPONSE:
        ResponseMsg responseMsg = (ResponseMsg) msg;
        if (responseMsg.getRequestId() >= 0) {
          logger.debug("[{}] Pending request processed: {}", responseMsg.getRequestId(), responseMsg);
          pendingMap4Asset.remove(responseMsg.getRequestId());
        }
        break;
      }
      sessionCtx.onMsg(new BasicSessionActorToAdaptorMsg(this.sessionCtx, msg));
    } else {
      sessionCtx.onMsg(org.iotp.analytics.ruleengine.common.msg.session.ctrl.SessionCloseMsg
          .onCredentialsRevoked(sessionCtx.getSessionId()));
    }
  } catch (SessionException e) {
    logger.warning("Failed to push session response msg", e);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:ASyncMsgProcessor.java

示例9: pushToNextRule

import akka.actor.ActorContext; //导入依赖的package包/类
private void pushToNextRule(ActorContext context, ChainProcessingContext ctx, RuleEngineError error) {
  if (error != null) {
    ctx = ctx.withError(error);
  }
  if (ctx.isFailure()) {
    logger.debug("[{}][{}] Forwarding processing chain to device actor due to failure.", ruleMd.getId(),
        ctx.getInMsg().getDeviceId());
    ctx.getDeviceActor().tell(new RulesProcessedMsg(ctx), ActorRef.noSender());
  } else if (!ctx.hasNext()) {
    logger.debug("[{}][{}] Forwarding processing chain to device actor due to end of chain.", ruleMd.getId(),
        ctx.getInMsg().getDeviceId());
    ctx.getDeviceActor().tell(new RulesProcessedMsg(ctx), ActorRef.noSender());
  } else {
    logger.debug("[{}][{}] Forwarding processing chain to next rule actor.", ruleMd.getId(),
        ctx.getInMsg().getDeviceId());
    ChainProcessingContext nextTask = ctx.getNext();
    nextTask.getCurrentActor().tell(new RuleProcessingMsg(nextTask), context.self());
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:20,代码来源:RuleActorMessageProcessor.java

示例10: onActivate

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void onActivate(ActorContext context) throws Exception {
  logger.info("[{}] Going to process onActivate rule.", entityId);
  this.state = ComponentLifecycleState.ACTIVE;
  if (filters != null) {
    filters.forEach(RuleLifecycleComponent::resume);
    if (processor != null) {
      processor.resume();
    } else {
      initProcessor();
    }
    if (action != null) {
      action.resume();
    }
    logger.info("[{}] Rule resumed.", entityId);
  } else {
    start();
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:20,代码来源:RuleActorMessageProcessor.java

示例11: onUpdate

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void onUpdate(ActorContext context) throws Exception {
    PluginMetaData oldPluginMd = pluginMd;
    pluginMd = systemContext.getPluginService().findPluginById(entityId);
    boolean requiresRestart = false;
    logger.info("[{}] Plugin configuration was updated from {} to {}.", entityId, oldPluginMd, pluginMd);
    if (!oldPluginMd.getClazz().equals(pluginMd.getClazz())) {
        logger.info("[{}] Plugin requires restart due to clazz change from {} to {}.",
                entityId, oldPluginMd.getClazz(), pluginMd.getClazz());
        requiresRestart = true;
    } else if (!oldPluginMd.getConfiguration().equals(pluginMd.getConfiguration())) {
        logger.info("[{}] Plugin requires restart due to configuration change from {} to {}.",
                entityId, oldPluginMd.getConfiguration(), pluginMd.getConfiguration());
        requiresRestart = true;
    }
    if (requiresRestart) {
        this.state = ComponentLifecycleState.SUSPENDED;
        if (pluginImpl != null) {
            pluginImpl.stop(trustedCtx);
        }
        start();
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:24,代码来源:PluginActorMessageProcessor.java

示例12: sendPendingRequests

import akka.actor.ActorContext; //导入依赖的package包/类
private void sendPendingRequests(ActorContext context, SessionId sessionId, SessionType type, Optional<ServerAddress> server) {
    if (!rpcPendingMap.isEmpty()) {
        logger.debug("[{}] Pushing {} pending RPC messages to new async session [{}]", deviceId, rpcPendingMap.size(), sessionId);
        if (type == SessionType.SYNC) {
            logger.debug("[{}] Cleanup sync rpc session [{}]", deviceId, sessionId);
            rpcSubscriptions.remove(sessionId);
        }
    } else {
        logger.debug("[{}] No pending RPC messages for new async session [{}]", deviceId, sessionId);
    }
    Set<Integer> sentOneWayIds = new HashSet<>();
    if (type == SessionType.ASYNC) {
        rpcPendingMap.entrySet().forEach(processPendingRpc(context, sessionId, server, sentOneWayIds));
    } else {
        rpcPendingMap.entrySet().stream().findFirst().ifPresent(processPendingRpc(context, sessionId, server, sentOneWayIds));
    }

    sentOneWayIds.forEach(rpcPendingMap::remove);
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:20,代码来源:DeviceActorMessageProcessor.java

示例13: processPendingRpc

import akka.actor.ActorContext; //导入依赖的package包/类
private Consumer<Map.Entry<Integer, ToDeviceRpcRequestMetadata>> processPendingRpc(ActorContext context, SessionId sessionId, Optional<ServerAddress> server, Set<Integer> sentOneWayIds) {
    return entry -> {
        ToDeviceRpcRequest request = entry.getValue().getMsg().getMsg();
        ToDeviceRpcRequestBody body = request.getBody();
        if (request.isOneway()) {
            sentOneWayIds.add(entry.getKey());
            ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(entry.getValue().getMsg(), (String) null);
            context.parent().tell(responsePluginMsg, ActorRef.noSender());
        }
        ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg(
                entry.getKey(),
                body.getMethod(),
                body.getParams()
        );
        ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(rpcRequest, sessionId);
        sendMsgToSessionActor(response, server);
    };
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:19,代码来源:DeviceActorMessageProcessor.java

示例14: processSubscriptionCommands

import akka.actor.ActorContext; //导入依赖的package包/类
private void processSubscriptionCommands(ActorContext context, ToDeviceActorMsg msg) {
    SessionId sessionId = msg.getSessionId();
    SessionType sessionType = msg.getSessionType();
    FromDeviceMsg inMsg = msg.getPayload();
    if (inMsg.getMsgType() == MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) {
        logger.debug("[{}] Registering attributes subscription for session [{}]", deviceId, sessionId);
        attributeSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress()));
    } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST) {
        logger.debug("[{}] Canceling attributes subscription for session [{}]", deviceId, sessionId);
        attributeSubscriptions.remove(sessionId);
    } else if (inMsg.getMsgType() == MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST) {
        logger.debug("[{}] Registering rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType);
        rpcSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress()));
        sendPendingRequests(context, sessionId, sessionType, msg.getServerAddress());
    } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST) {
        logger.debug("[{}] Canceling rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType);
        rpcSubscriptions.remove(sessionId);
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:20,代码来源:DeviceActorMessageProcessor.java

示例15: processToDeviceMsg

import akka.actor.ActorContext; //导入依赖的package包/类
@Override
public void processToDeviceMsg(ActorContext context, ToDeviceMsg msg) {
    try {
        if (msg.getMsgType() != MsgType.SESSION_CLOSE) {
            switch (msg.getMsgType()) {
                case STATUS_CODE_RESPONSE:
                case GET_ATTRIBUTES_RESPONSE:
                    ResponseMsg responseMsg = (ResponseMsg) msg;
                    if (responseMsg.getRequestId() >= 0) {
                        logger.debug("[{}] Pending request processed: {}", responseMsg.getRequestId(), responseMsg);
                        pendingMap.remove(responseMsg.getRequestId());
                    }
                    break;
                default:
                    break;
            }
            sessionCtx.onMsg(new BasicSessionActorToAdaptorMsg(this.sessionCtx, msg));
        } else {
            sessionCtx.onMsg(org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg.onCredentialsRevoked(sessionCtx.getSessionId()));
        }
    } catch (SessionException e) {
        logger.warning("Failed to push session response msg", e);
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:25,代码来源:ASyncMsgProcessor.java


注:本文中的akka.actor.ActorContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。