Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 Red Hat, Inc, and individual contributors.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.projectodd.stilts.stomplet;
 
Defines methods that all Stomplets must implement.

A Stomplet is a small Java class that performs two functions related to asynchronous message processing:

  1. Handle requests from clients to subscribe and unsubscribe from matching destinations
  2. Receive messages sent to the destination from clients, and handle dispatching outbound messages to subscribers.

A single Stomplet may be configured to services multiple destinations based upon routing rules.

Author(s):
Bob McWhirter
See also:
http://stilts.projectodd.org/stomplet/
 
 public interface Stomplet {

    
Initialize the Stomplet in its container environment

Parameters:
config The configuration for the stomplet.
Throws:
org.projectodd.stilts.stomp.StompException If an error occurs during initialization.
 
     void initialize(StompletConfig configthrows StompException;

    
Clean up any resources allocated by the stomplet before removing it from the container.

Throws:
org.projectodd.stilts.stomp.StompException If an error occurs during destruction.
 
     void destroy() throws StompException;

    
Handle a message sent to a destination matched by this stomplet.

In the event the stomplet is servicing multiple destinations, the stomplet may need to inspect the org.projectodd.stilts.stomp.StompMessage for details as to how to handle the incoming message.

If named-segments are present in the applicable routing rule, each named segment is added to the message's header values, prefixed with stomplet..

For instance, the following routing rule:

 ROUTE /queues/:queue_name com.mycorp.MyStomplet
 

Would result in all inbound messages with matching destinations to have a header named stomplet.queue_name added to it, with the value being the matching portion of the destination.

Parameters:
message The inbound message.
session The user session.
Throws:
org.projectodd.stilts.stomp.StompException If an error occurs while processing the message.
 
     void onMessage(StompMessage messageStompSession sessionthrows StompException;

    
Handle a subscription request.

For subscription requests matching destinations mapped to this stomplet, the onSubscribe(org.projectodd.stilts.stomplet.Subscriber) method will be invoked with a Subscriber object. If the stomplet chooses to allow the subscription, it may route further messages to the Subscriber to satisfy the subscription.

If it chooses to deny the subscription request (for any reason), throwing a StompException is appropriate.

Parameters:
subscriber The live subscriber making the request.
Throws:
org.projectodd.stilts.stomp.StompException If an error occurs processing the subscription request.
    void onSubscribe(Subscriber subscriberthrows StompException;

    
Handle the cancellation of a subscription.

When a client explicitly cancels a subscription, or disconnects, the stomplet is notified through onUnsubscribe(org.projectodd.stilts.stomplet.Subscriber), having the same Subscriber instance passed to it.

Parameters:
subscriber The subscriber cancelling the subscription.
Throws:
org.projectodd.stilts.stomp.StompException If an error occurs processing the subscription cancellation request.
    void onUnsubscribe(Subscriber subscriberthrows StompException;
New to GrepCode? Check out our FAQ X