|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.enhydra.barracuda.core.event.ApplicationGateway
The application gateway is responsible for a number of things.
Consequently, if you want to use the Barracuda event model, this is the class that really kicks it all off. You must either extend this class OR use the DefaultApplicationAssembler in order to specify that this servlet handles all event requests for an application. This will allow the system to convert requests to events and dispatch them through the EventBroker to any listeners within EventGateways that have registered interest with the broker.
This class should be the first servlet loaded in your web.xml file.
For an example of how to do this, look at org.enhydra.barracuda.examples.ex1.SampleApplicationGateway
You might also want to look at the UML Class diagram of the Event model classes.
Field Summary | |
protected EventGateway |
eventGateway
|
static String |
EXTERNAL_CONTEXT_OBJ_NAME
|
protected List |
gateways
|
static String |
HTTP_SERVLET_REQUEST
|
static String |
HTTP_SERVLET_RESPONSE
|
static String |
LONG_RUNNING_ID
|
static int |
LR_DEBUG
|
static String |
LR_OVERRIDE_KEY
|
static RequestWrapper |
REQUEST_WRAPPER
|
static boolean |
RESPOND_WITH_404
|
static ResponseWrapper |
RESPONSE_WRAPPER
|
static String |
TARGET_EVENT_NAME
|
static String |
THREAD_POOL
|
static boolean |
USE_EVENT_POOLING
|
protected boolean |
virgin
|
Constructor Summary | |
ApplicationGateway()
Public noargs constructor |
Method Summary | |
void |
add(EventGateway eg)
Add an event gateway to this one |
void |
deregister(EventBroker eb)
Ask all interested parties to de-register with the EventBroker |
void |
deregisterLocalEventInterests(EventBroker eb)
Deregister any local interests in the EventBroker |
void |
destroy()
Here's where we destroy the servlet. |
void |
destroyLocal()
Perform any local cleanup (this is where you should remove any known EventGateways) |
protected void |
doDelete(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the DELETE request is mapped to the handleDefault method |
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the GET request is mapped to the handleDefault method |
protected void |
doOptions(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the OPTIONS request is mapped to the handleDefault method |
protected void |
doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the POST request is mapped to the handleDefault method |
protected void |
doPut(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the PUT request is mapped to the handleDefault method |
protected void |
doTrace(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
By default the TRACE request is mapped to the handleDefault method |
List |
getChildren()
Get a list of child gateways. |
DispatcherFactory |
getDispatcherFactory()
Provide an instance of the specific EventDispatcher we want to use. |
EventBroker |
getEventBroker()
Provide a reference to the event broker. |
String |
getEventExtension()
Indicate which event extension we are handling. |
EventPool |
getEventPool()
Provide a reference to the event pool. |
DispatchQueue |
getNewDispatchQueueInstance()
Provide an instance of the specific DispatchQueue we want to use. |
EventBroker |
getNewEventBrokerInstance()
Provide an instance of the specific EventBroker we want to use. |
EventGateway |
getParent()
Get the parent gateway. |
void |
handleDefault(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Handle the default HttpRequest. |
void |
handleDefaultExt(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Object externalContextObj)
Handle the default HttpRequest with the ability to add the provided object into the context. |
void |
handleEventException(EventException e,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Handle an EventException. |
void |
init()
Here's where we initialize the servlet. |
void |
initializeLocal()
Perform any local initialization (this is where you should add any other known EventGateways) |
void |
initializeLocal(javax.servlet.ServletConfig iconfig)
Deprecated. If your code is still attempting to extend this old method signature, you need to change it to use initializeLocal() instead. If you still need to get a reference to the servlet config, just call 'this.getServletConfig()'. This method is now final so that code which might still be using it will no longer compile. |
void |
register(EventBroker eb)
Ask all interested parties to register with the EventBroker |
void |
registerLocalEventAliases(EventBroker eb)
Register any local event aliases in the EventBroker |
void |
registerLocalEventInterests(EventBroker eb)
Register any local interests in the EventBroker |
void |
remove(EventGateway eg)
Remove an event gateway from this one |
void |
setParent(EventGateway eg)
Set the parent gateway. |
void |
specifyEventGateways(EventGateway gateway)
Specify event gateways. |
void |
specifyLocalEventAliases(Class event)
Rather than overriding the registerLocalEventAliases method, you can just invoke this method instead for type of event you want to manually alias. |
void |
specifyLocalEventInterests(ListenerFactory factory)
Rather than overriding the registerLocalEventInterests method, you can just invoke this method instead for each interest you'd like to register. |
void |
specifyLocalEventInterests(ListenerFactory factory,
Class event)
Rather than overriding the registerLocalEventInterests method, you can just invoke this method instead for each interest you'd like to register. |
protected javax.servlet.http.HttpServletRequest |
wrapRequest(javax.servlet.http.HttpServletRequest req)
|
protected javax.servlet.http.HttpServletResponse |
wrapResponse(javax.servlet.http.HttpServletResponse resp)
|
Methods inherited from class javax.servlet.http.HttpServlet |
doHead, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static boolean USE_EVENT_POOLING
public static boolean RESPOND_WITH_404
public static RequestWrapper REQUEST_WRAPPER
public static ResponseWrapper RESPONSE_WRAPPER
public static String LR_OVERRIDE_KEY
public static int LR_DEBUG
public static final String HTTP_SERVLET_REQUEST
public static final String HTTP_SERVLET_RESPONSE
public static final String THREAD_POOL
public static final String TARGET_EVENT_NAME
public static final String EXTERNAL_CONTEXT_OBJ_NAME
public static final String LONG_RUNNING_ID
protected EventGateway eventGateway
protected List gateways
protected boolean virgin
Constructor Detail |
public ApplicationGateway()
Method Detail |
public void initializeLocal()
Perform any local initialization (this is where you should add any other known EventGateways)
public final void initializeLocal(javax.servlet.ServletConfig iconfig) throws javax.servlet.ServletException
Perform any local initialization (this is where you should add any other known EventGateways)
iconfig
- the ServletConfig object used to configure this servlet
javax.servlet.ServletException
public void destroyLocal()
Perform any local cleanup (this is where you should remove any known EventGateways)
public EventBroker getNewEventBrokerInstance()
Provide an instance of the specific EventBroker we want to use. Override this method if you'd like to use something other than the DefaultEventBroker.
public DispatchQueue getNewDispatchQueueInstance()
Provide an instance of the specific DispatchQueue we want to use. Override this method if you'd like to use something other than the DefaultDispatchQueue.
public DispatcherFactory getDispatcherFactory()
Provide an instance of the specific EventDispatcher we want to use. Override this method if you'd like to use something other than DefaultEventBroker.
public String getEventExtension()
Indicate which event extension we are handling. By default the gateway handles extensions of .event. If you wish to handle a different function you should override this method to return the value defined in the web.xml file.
public void handleDefault(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
Handle the default HttpRequest. It will probably be rare for developers to override this.
Basically, this method receives a request and attempts to map it to a valid HttpRequestEvent. If the event is invalid, or if the event is NOT an instance of HttpRequestEvent, then we simply create a new instance of HttpRequestEvent and dispatch that instead. This is a very important feature, because it allows us to define events which are not accessible to the outside world -- the gateway will only dispatch HttpRequest events, so you define your publically accessible API by creating an event hierarchy that extends from the HttpRequestEvent object.
Once we have a valid event, we dispatch it. In this case (because this is an Http gateway) we must have a response, so if we catch an UnhandledEventException, we will generate a default error message and return.
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
public void handleDefaultExt(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, Object externalContextObj) throws javax.servlet.ServletException, IOException
Handle the default HttpRequest with the ability to add the provided object into the context. It will probably be rare for developers to override this.
Basically, this method receives a request and attempts to map it to a valid HttpRequestEvent. If the event is invalid, or if the event is NOT an instance of HttpRequestEvent, then we simply create a new instance of HttpRequestEvent and dispatch that instead. This is a very important feature, because it allows us to define events which are not accessible to the outside world -- the gateway will only dispatch HttpRequest events, so you define your publically accessible API by creating an event hierarchy that extends from the HttpRequestEvent object.
Once we have a valid event, we dispatch it. In this case (because this is an Http gateway) we must have a response, so if we catch an UnhandledEventException, we will generate a default error message and return.
req
- the servlet requestresp
- the servlet responseexternalContextObj
- object to put into the context
javax.servlet.ServletException
IOException
public void handleEventException(EventException e, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
Handle an EventException. Basically, this is where we handle the really bad, unexpected type of event exceptions. Generally, as you code, if you want to interrupt the dispatch and fire a new event, you should throw an InterruptDispatchException. Only throw EventExceptions in truly exceptional circumstances.
e
- the EventException to handlereq
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
public final void specifyEventGateways(EventGateway gateway)
Specify event gateways. You can call this method with as many different gateways as you like. When the Application Gateway initializes, it will load them all. When the gateway is destroyed, they will be deregistered.
gateway
- an event gateway we'd like to have registeredpublic final EventBroker getEventBroker()
Provide a reference to the event broker.
public final EventPool getEventPool()
Provide a reference to the event pool. May return null if we're not using event pooling.
protected javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest req)
protected javax.servlet.http.HttpServletResponse wrapResponse(javax.servlet.http.HttpServletResponse resp)
public final void setParent(EventGateway eg)
Set the parent gateway. Null indicates its the root. By definition, an ApplicationGateway is always the root.
setParent
in interface EventGateway
eg
- the parent event gateway for this gatewaypublic final EventGateway getParent()
Get the parent gateway. Returns null if it's the root.
getParent
in interface EventGateway
public final void add(EventGateway eg)
Add an event gateway to this one
add
in interface EventGateway
eg
- the event gateway to be addedpublic final void remove(EventGateway eg)
Remove an event gateway from this one
remove
in interface EventGateway
eg
- the event gateway to be removedpublic List getChildren()
getChildren
in interface EventGateway
public final void register(EventBroker eb)
Ask all interested parties to register with the EventBroker
register
in interface EventGateway
eb
- the event broker to register withpublic final void deregister(EventBroker eb)
Ask all interested parties to de-register with the EventBroker
deregister
in interface EventGateway
eb
- the event broker to de-register withpublic final void registerLocalEventInterests(EventBroker eb)
registerLocalEventInterests
in interface EventGateway
eb
- the event broker this gateway should use to
register for local eventspublic final void deregisterLocalEventInterests(EventBroker eb)
deregisterLocalEventInterests
in interface EventGateway
eb
- the event broker this gateway should use to
de-register for local eventspublic final void registerLocalEventAliases(EventBroker eb)
registerLocalEventAliases
in interface EventGateway
eb
- the event broker this gateway should use to
register aliases for local eventspublic final void specifyLocalEventInterests(ListenerFactory factory)
specifyLocalEventInterests
in interface EventGateway
factory
- the factory we wish to register with the event brokerpublic final void specifyLocalEventInterests(ListenerFactory factory, Class event)
specifyLocalEventInterests
in interface EventGateway
factory
- the factory we wish to register with the event brokerevent
- the class of events we are interested inpublic final void specifyLocalEventAliases(Class event)
specifyLocalEventAliases
in interface EventGateway
event
- the class of events we are interested in registering
aliases forprotected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the GET request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the POST request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
protected void doOptions(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the OPTIONS request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
protected void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the DELETE request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
protected void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the PUT request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
protected void doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
By default the TRACE request is mapped to the handleDefault method
req
- the servlet requestresp
- the servlet response
javax.servlet.ServletException
IOException
public void init() throws javax.servlet.ServletException
Here's where we initialize the servlet.
javax.servlet.ServletException
public void destroy()
Here's where we destroy the servlet.
destroy
in interface javax.servlet.Servlet
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |