建立SOA架构中的事件驱动服务 (6)
[ 来源:互网络 | 更新日期:2007-09-06 04:30:52 | 浏览次数:15814]
简介:及时响应实时的变化和事件成为了企业级架构的最重要需求。这篇文章讨论面向服务框架的技术和机制,这些技术使得该框架高效发送、接受那些跨越层级结构的同步和异步事件,而不需要知道产生这些事件的系统方面的细节
message is to be sent.
* @param payload
The content of the event message.
* @return FutureMessageResult The result, if any.
* @throws EventException on error
*/ public FutureMessageResult sendAsynchronousEvent(String serviceName,
Object payload)
throws EventException;
/**
* Starts this event manager.
*/
public void start();
/**
* Stops this event manager.
*/
public void stop();
/**
* Retrieves the protocol this event manager uses.
* @return
*/
public String getProtocol();
/**
* 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.
*/ public void registerService(String serviceName,
String implementation)
throws EventException;
/**
* Unregisters a service from receiving event messages. * * @param serviceName The name associated with the service to unregister. */ public void unregisterService(String serviceName) throws EventException;}
事件管理器类是被封装在一个工厂类里,因此,可以依据需要去改变它的实现而不会影响到它的客户端。事件管理器实现如下:
package com.jeffhanson.mule;import org.mule.umo.*;
import org.mule.extras.client.MuleClient;
import org.mule.impl.endpoint.MuleEndpoint;
import org.mule.config.QuickConfigurationBuilder;
import java.util.HashMap;
import java.util.Map;
public class EventManagerFactory{ private static HashMap instances = new HashMap();
/**
* Retrieves the event manager instance for a given protocol.
*
* @param protocol
The protocol to use.
* @return EventManager The event manager instance.
*/ public static EventManager getInstance(String protocol)
{
EventManager instance = (EventManager)instances.get(protocol);
if (instance == null)
{
instance = new EventManagerImpl(protocol);
instances.put(protocol, instance);
}
return instance;
}
/**
* A concrete implementation for a simple event manager.
*/ private static class EventManagerImpl
implements EventManager
{
private UMOManager manager = null;
private QuickConfigurationBuilder builder = null;
private MuleClient eventClient = null;
private String protocol = null;
private MuleEndpoint receiveEndpoint = null;
private MuleEndpoint sendEndpoint = null;
private EventManagerImpl(String protocol)
{
this.protocol = protocol;
}
/**
* Starts this event manager.
*/
public void start()
{
try
{
builder = new QuickC


您的位置:
