您的位置:jsp学习站首页 >> JAVA类 >> JAVA高级 >> 建立SOA架构中的事件驱动服务

建立SOA架构中的事件驱动服务 (7)

[ 来源:互网络 | 更新日期:2007-09-06 04:30:52 | 浏览次数:15814]
简介:及时响应实时的变化和事件成为了企业级架构的最重要需求。这篇文章讨论面向服务框架的技术和机制,这些技术使得该框架高效发送、接受那些跨越层级结构的同步和异步事件,而不需要知道产生这些事件的系统方面的细节
onfigurationBuilder();
  manager = builder.createStartedManager(true,
  protocol + "tmp/events");
  eventClient = new MuleClient();
  receiveEndpoint = new MuleEndpoint(protocol
  + "tmp/events/receive");
  sendEndpoint = new MuleEndpoint(protocol + "tmp/events/send");
  }
  catch (UMOException e)
  {
  System.err.println(e);
  }
  }
  /**
  * Stops this event manager.
  */
  public void stop()
  {
  try
  {
  manager.stop();
  }     catch (UMOException e)
  {
  System.err.println(e);
  }
  }
  /**
  * Retrieves the protocol this event manager uses.
  * @return
  */
  public String getProtocol()
  {
  
  return protocol;
  }   /**
  * Registers a service to receive event messages.
  *
  * @param serviceName
  The name to associate with the service.
  * @param implementation
  Either a container reference to the service
  *
  or a fully-qualified class name
  *
  to use as the component implementation.
  */
  public void registerService(String serviceName,
  String implementation)
  throws EventException
  {
  if (!manager.getModel().isComponentRegistered(serviceName))
  {
  try
  {
  builder.registerComponent(implementation,
  serviceName,
  receiveEndpoint,
  sendEndpoint);
  }
  catch (UMOException e)
  {
  throw new EventException(e.toString());
  }
  }
  }   /**
  * Unregisters a service from receiving event messages.
  *
  * @param serviceName The name associated with the service to unregister.
  */
  public void unregisterService(String serviceName)
  throws EventException
  {
  try
  {
  builder.unregisterComponent(serviceName);
  }
  catch (UMOException e)
  {
  throw new EventException(e.toString());
  }
  }
  /**
  * Sends an event message synchronously to a given service.
  *
  * @param serviceName
  The name of the service to which the event
  *
  message is to be sent.
  * @param payload
  The content of the event message
  * @return Object
  The result, if any.
  * @throws EventException on error
  */
  public Object sendSynchronousEvent(String serviceName,
  Object payload)
  throws EventException
  {
  try
  {
  if (!manager.getModel().isComponentRegistered(serviceName))
  {
  throw new EventException("Service: " + serviceName
  + " is not registered.");
  }
  String transformers = null;
  
  Map messageProperties = null;
  UMOMessage result = eventClient.sendDirect(serviceName,
  transformers,
  payload,
  messageProperties);
  if (result == null)
  {
  return
[1] [2] [3] [4] [5] [6] [7] [8] [9]
Tags:关键字:架构
责任编辑:glen