org.tinygroup.event.Event类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.tinygroup.event.Event类的一些代码示例,展示了Event类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event类的具体详情如下:
包路径:org.tinygroup.event.Event
类名称:Event

Event介绍

[英]事件
一个事件,可以是一个服务请求,也可以是多个
[中]事件
一个事件,可以是一个服务请求,也可以是多个

代码示例

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

public static String getServiceId(Event event){
    return event.getServiceRequest().getServiceId();
  }
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

private Event getAsynchronousResponseEvent(Event event) {
  Event response = new Event();
  response.setEventId(event.getEventId());
  response.setMode(Event.EVENT_MODE_ASYNCHRONOUS);
  response.setType(Event.EVENT_TYPE_RESPONSE);
  return response;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.imda

private Event getEvent(Context context, String serviceId) {
    Event event = new Event(UUID.randomUUID().toString()
        .replaceAll("-", ""));
    ServiceRequest serviceRequest = new ServiceRequest();
    event.setServiceRequest(serviceRequest);
    serviceRequest.setServiceId(serviceId);
    serviceRequest.setContext(context);
    return event;
  }
}

代码示例来源:origin: org.tinygroup/event

public static Event createEvent(String serviceId, String nodeName,
    Context context) {
  Event event = createEvent(serviceId, context);
  event.getServiceRequest().setNodeName(nodeName);
  return event;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorebase

private void putThreadVariable(Event event) {
  ServiceRequest request = event.getServiceRequest();
  LoggerFactory.putThreadVariable(LoggerFactory.SERVICE_EVENTID, event.getEventId());
  LoggerFactory.putThreadVariable(LoggerFactory.SERVICE_SERVICEID, request.getServiceId());
}

代码示例来源:origin: org.tinygroup/weblayer

private Object callService(String serviceId, Context context) {
  CEPCore core = SpringUtil.getBean(CEPCore.CEP_CORE_BEAN);
  Event event = new Event();
  ServiceRequest sq = new ServiceRequest();
  sq.setServiceId(serviceId);
  sq.setContext(context);
  event.setServiceRequest(sq);
  core.process(event);
  ServiceInfo info = core.getServiceInfo(serviceId);
  List<Parameter> resultsParam = info.getResults();
  if (resultsParam.size() == 0) {
    return null;
  }
  return event.getServiceRequest().getContext()
      .get(resultsParam.get(0).getName());
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

String eventId = event.getEventId();
String serviceId = event.getServiceRequest().getServiceId();
if (event.getMode() == Event.EVENT_MODE_ASYNCHRONOUS) {
  event.setType(Event.EVENT_TYPE_RESPONSE);
  ctx.writeAndFlush(event);
} catch (RuntimeException e) {
  logger.errorMessage("远程请求{0}:{1}发生异常", e, eventId, serviceId);
  event.setThrowable(e);
} catch (Error r) {
  event.setThrowable(r);
} finally {
  if (ctx != null) {
    event.setType(Event.EVENT_TYPE_RESPONSE);
    ctx.writeAndFlush(event);
    logger.logMessage(LogLevel.INFO, "远程请求已写出{0}:{1}", eventId,

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

public void channelRead(ChannelHandlerContext ctx, Object msg)
    throws Exception {
  Event event = (Event) msg;
  String serviceId = event.getServiceRequest().getServiceId();
  logger.logMessage(LogLevel.INFO, "接收到请求,id:{},type:{}", serviceId,
      event.getType());
  boolean isResponse = (Event.EVENT_TYPE_RESPONSE == event.getType());
  if (isResponse) {
    processResult(event, ctx); // 处理服务的返回结果
  } else {
    logger.errorMessage("客户端收到未知请求" + serviceId);
  }
}

代码示例来源:origin: org.tinygroup/org.tinygroup.servicehttpchannel

public void process(Event event) {
  if (serverPath == null) {
    throw new RuntimeException("服务器地址路径未配置");
  }
  String serviceId = event.getServiceRequest().getServiceId();
  String url = serverPath + serviceId + ".mockservice";
  Event result = execute(event, url);
  Throwable throwable = result.getThrowable();
  if (throwable != null) {// 如果有异常发生,则抛出异常
    LOGGER.errorMessage("服务执行发生异常,serviceId:{},eventId:{}", throwable,
        result.getServiceRequest().getServiceId(),
        result.getEventId());
    if (throwable instanceof RuntimeException) {
      throw (RuntimeException) throwable;
    } else {
      throw new RuntimeException(throwable);// 此处的RuntimeException类型需要调整
    }
  }
  event.getServiceRequest()
      .getContext()
      .putSubContext(result.getEventId(),
          result.getServiceRequest().getContext());
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

protected void processObject(Object message, ChannelHandlerContext ctx) {
  String eventId = event.getEventId();
  eventMap.put(eventId, event);
  channelHandlerContextMap.put(eventId, ctx);
  if (NettyCepCoreUtil.AR_TO_SC.equals(serviceId)) { // AR向Sc发起
    logger.logMessage(LogLevel.INFO, "请求{}由普通节点发向服务中心", serviceId);
    Context c = event.getServiceRequest().getContext();
    Node remoteNode = c.get(NettyCepCoreUtil.NODE_KEY);
    logger.logMessage(LogLevel.INFO, "发起节点:{}", remoteNode.toString());
    clearRequest(event.getEventId());
    event.setType(Event.EVENT_TYPE_RESPONSE);
    ctx.getChannel().write(event);
    Context c = event.getServiceRequest().getContext();
    String type = c.get(NettyCepCoreUtil.TYPE_KEY);
    if (NettyCepCoreUtil.REG_KEY.equals(type)) {
    clearRequest(event.getEventId());
    event.setType(Event.EVENT_TYPE_RESPONSE);
    ctx.getChannel().write(event);
  } else {

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

public void channelRead(ChannelHandlerContext ctx, Object msg)
    throws Exception {
  Event event = (Event) msg;
  String serviceId = event.getServiceRequest().getServiceId();
  logger.logMessage(LogLevel.INFO, "接收到请求,id:{},type:{}", serviceId,
      event.getType());
  boolean isResponse = (Event.EVENT_TYPE_RESPONSE == event.getType());
  if (CEPCoreEventHandler.NODE_RE_REG_TO_SC_REQUEST.equals(serviceId)
    ResponseManager.updateResponse(event.getEventId(), event);
  } else if (CEPCoreEventHandler.NODE_REG_TO_SC_REQUEST.equals(serviceId)
    ResponseManager.updateResponse(event.getEventId(), event);
  } else if (CEPCoreEventHandler.SC_REG_NODE_TO_NODE_REQUEST

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

public void dealNodeUnregToSc(Event event, ChannelHandlerContext ctx) {
  logger.logMessage(LogLevel.INFO, "开始处理节点向服务中心发起的注销请求");
  Context c = event.getServiceRequest().getContext();
  Node remoteNode = c.get(NODE_KEY);
  String nodeString = remoteNode.toString();
  // 从节点缓存中移出当前节点
  Node currentNode = nodes.remove(nodeString);
  nodeServices.remove(nodeString);
  // 从链接缓存中移出当前链接,避免后续循环会向自己发送自己
  ctxs.remove(nodeString);
  // 将该注销消息推送至其它节点
  scUnregCurrentNodeToNodes(nodeString, currentNode);
  // 返回SC上其它的节点信息
  event.setType(Event.EVENT_TYPE_RESPONSE);
  c.put(NODES_KEY, nodes);
  ctx.writeAndFlush(event);
  ctx.close();
  logger.logMessage(LogLevel.INFO, "处理节点向服务中心发起的注销请求完成");
}

代码示例来源:origin: org.tinygroup/org.tinygroup.servicewrapper

private Event getEvent(String serviceId, Context context) throws Exception {
  Event event = new Event();
  event.setEventId(UUID.randomUUID().toString());
  ServiceRequest serviceRequest = new ServiceRequest();
  serviceRequest.setContext(context);
  serviceRequest.setServiceId(serviceId);
  try {
    String nodeName = InvokeNodeSetter.getNodeName();
    int eventMode = EventModeSetter.getEventMode();
    if (!StringUtil.isBlank(nodeName)) {
      serviceRequest.setNodeName(nodeName);
    }
    event.setMode(eventMode);
  } finally {
    InvokeNodeSetter.removeNodeName();
    EventModeSetter.removeEventMode();
  }
  event.setServiceRequest(serviceRequest);
  return event;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

protected void processObject(Object message, ChannelHandlerContext ctx) {
  Event event = (Event) message;
  // 更新事件
  String eventId = event.getEventId();
  EventClient eventClient = (EventClient) client;
  Event oldEvent = eventClient.getEvent(eventId);
  if (oldEvent != null) {// 如果事件已经不再存在,则直接忽略
    String oldEventId = oldEvent.getEventId();
    synchronized (oldEventId) {
      eventClient.updateEvent(oldEventId, event);
      // 提醒事件完成
      oldEventId.notify();
    }
  }
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

public void run(Event event) {
  ChannelHandlerContext channelHandlerContext = channelHandlerContextMap
      .get(event.getEventId());
    if (event.getMode() == Event.EVENT_MODE_ASYNCHRONOUS) {
      event.setType(Event.EVENT_TYPE_RESPONSE);
      channelHandlerContext.getChannel().write(
          getAsynchronousResponseEvent(event));
    core.process(event);
    channelHandlerContext = channelHandlerContextMap.get(event
        .getEventId());
    if (event.getMode() == Event.EVENT_MODE_SYNCHRONOUS) {
      if (channelHandlerContext != null) {
        event.setType(Event.EVENT_TYPE_RESPONSE);
        channelHandlerContext.getChannel().write(event);
  clearRequest(event.getEventId());

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcorenettysc

String eventId = event.getEventId();
    int priority = event.getPriority();
    if (priority < 0) {
      priority = 0;
    throw new RuntimeException("请求" + eventId + "调用时,超时.");
  Throwable throwable = e.getThrowable();
  if (throwable != null) {// 如果有异常发生,则抛出异常
    if (throwable instanceof RuntimeException) {

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

/**
 * 创建节点注册Event
 * 
 * @return
 */
private Event getNodeUnregRequestEvent() {
  Context c = new ContextImpl();
  c.put(NODE_KEY, getNode());
  Event e = Event.createEvent(NODE_UNREG_TO_SC_REQUEST, c);
  return e;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

throw e;
Throwable throwable = result.getThrowable();
if (throwable != null) {// 如果有异常发生,则抛出异常
  if (throwable instanceof RuntimeException) {

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcoremutiremoteimpl

protected void processResult(Object response, ChannelHandlerContext ctx)
    throws Exception {
  Event event = (Event) response;
  String eventId = event.getEventId();
  logger.logMessage(LogLevel.INFO, "接收到Event:{0}的请求响应,请求id:{1}", eventId,
      event.getServiceRequest().getServiceId());
  ResponseManager.updateResponse(eventId, event);
}

代码示例来源:origin: org.tinygroup/org.tinygroup.cepcore

public static Object execute(String serviceId, Object[] paramArray,
               ClassLoader loader) {
  CEPCore cepcore = BeanContainerFactory.getBeanContainer(loader)
      .getBean(CEPCore.CEP_CORE_BEAN);
  // 获取服务信息
  ServiceInfo serviceInfo = cepcore.getServiceInfo(serviceId);
  // 将服务参数值与key映射起来,组装一个context出来
  List<Parameter> params = serviceInfo.getParameters();
  Context context = ContextFactory.getContext();
  for (int i = 0; i < params.size(); i++) {
    context.put(params.get(i).getName(), paramArray[i]);
  }
  // 组装Event
  Event event = new Event();
  ServiceRequest request = new ServiceRequest();
  request.setServiceId(serviceId);
  request.setContext(context);
  event.setServiceRequest(request);
  cepcore.process(event);
  List<Parameter> result = serviceInfo.getResults();
  if (result == null || result.isEmpty())
    return null;
  return event.getServiceRequest().getContext()
      .get(result.get(0).getName());
}

相关文章