FileDocCategorySizeDatePackage
RMSource.javaAPI DocExample11350Tue May 29 16:56:42 BST 2007com.sun.xml.ws.rm.jaxws.runtime.client

RMSource

public class RMSource extends com.sun.xml.ws.rm.jaxws.runtime.RMProvider
An RMSource represents a Collection of RMSequences with a common acksTo endpoint.

Fields Summary
private static final Logger
logger
private static RMSource
rmSource
private long
retryInterval
private RetryTimer
retryTimer
Constructors Summary
public RMSource()

        
        retryInterval = 2000;
        
        retryTimer = new RetryTimer(this);
        
    
Methods Summary
public synchronized voidaddOutboundSequence(ClientOutboundSequence seq)

        logger.fine(Messages.ADDING_SEQUENCE_MESSAGE.format(seq.getId()));
        
        boolean firstSequence = outboundMap.isEmpty();
        outboundMap.put(seq.getId(), seq);
        
        ClientInboundSequence iseq = 
                    (ClientInboundSequence)seq.getInboundSequence();
            
        String iseqid = null;
       
        if (iseq != null && null != (iseqid = iseq.getId())) {
            inboundMap.put(iseqid, iseq);
        }
        if (firstSequence) {
            retryTimer.start();
        }
    
public ClientOutboundSequencecreateSequence(javax.xml.ws.Service service, javax.xml.namespace.QName portName)
Initialize a sequence using a CreateSequence handshake. The returned Sequence can be set in BindingProvider properies which will result in the Sequence being used for the BindingProvider's request messages.

param
client A Service hosting the endpoint
param
port The QName for the RM enpoint.
return
The ClientOutboundSequence. null if the sequence could not be created

   
        Dispatch<Source> disp = service.createDispatch(portName, 
                                                        Source.class, 
                                                        Service.Mode.PAYLOAD,
                                                        new javax.xml.ws.RespectBindingFeature());
        
        byte[] bytes = Constants.createSequencePayload.getBytes();
        ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
        StreamSource source = new StreamSource(stream);
        
        try {
            disp.invoke(source);
        } catch (Exception e) {
            
            //dont care what happened processing the response message.  We are only
            //interested in the sequence that has been stored in the request context
            //
            //TODO - At the same time, it would be prettier to get something other than
            //a fault
        }
        
        ClientOutboundSequence seq =  (ClientOutboundSequence)disp.getRequestContext()
                    .get(Constants.sequenceProperty);
        seq.setService(service);
        return seq;
       
    
public ClientOutboundSequencecreateSequence(javax.xml.ws.Service service, javax.xml.namespace.QName portName, java.lang.String sequenceID, java.lang.String companionSequenceID)
Initialize a sequence using an existing seuence id known to an RM endpoint. The method is designed to be used after a startup to reinitialize a sequence from persisted data.

param
client A Service hosting the endpoint
param
port The QName for the RM enpoing.
param
sequencID The id to be used for the outbound sequence
param
companionSequenceID The id to be used for the companion inbound sequence, if any
return
The ClientOutboundSequence. null if the sequence could not be created

        
   
        //this will throw and exception if the specified sequence does not exist.
        //removeOutboundSequence(sequenceID);
        
        ClientOutboundSequence seq = createSequence(service, portName);
        if (seq == null ) {
            return null;
        }
         
        try {
            seq.disconnect(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        seq.setId(sequenceID);
        
        ClientInboundSequence iseq = 
                    (ClientInboundSequence)seq.getInboundSequence();
        
        if (companionSequenceID != null) {
           
            if (iseq == null || iseq.getId() == null) {
                
                String message = Messages.NO_TWO_WAY_OPERATION.format();
                IllegalArgumentException e = new IllegalArgumentException(message);
                logger.log(Level.FINE, message, e);
                throw e;
            }     
            iseq.setId(companionSequenceID);
            
        } else if (iseq != null && iseq.getId() != null) {
            
            String message = Messages.NO_INBOUND_SEQUENCE_ID_SPECIFIED.format();
            IllegalArgumentException e = new IllegalArgumentException(message);
            logger.log(Level.FINE, message,e);
            throw e;
        }
        
        if (outboundMap.get(sequenceID) != null) {
            
            String message = Messages.SEQUENCE_ALREADY_EXISTS.format(sequenceID);
            IllegalArgumentException e = new IllegalArgumentException(message);
            logger.log(Level.FINE, message, e);
            throw e;
           
        }
        
        if (companionSequenceID != null &&
                inboundMap.get(companionSequenceID) != null) {
            
            String message = Messages.SEQUENCE_ALREADY_EXISTS.format(companionSequenceID);
            IllegalArgumentException e = new IllegalArgumentException(message);
            logger.log(Level.FINE, message, e);
            throw e;
           
        }
               
        addOutboundSequence(seq);
        
        return seq;
    
public voiddoMaintenanceTasks()
Do the necessary maintenance tasks for each ClientInboundSequence managed by this RMSource. This is done by calling the doMaintenanceTasks method of each managed sequence.

throws
RMException Propogates RMException thrown by any of the managed sequences.

        
        for (String key : outboundMap.keySet()) {
            
            ClientOutboundSequence seq =
                    getOutboundSequence(key);
            
            synchronized(seq) {
                //1. resend all incomplete messages
                //2. send ackRequested messages in any sequences
                //   in danger of timing out.
                seq.doMaintenanceTasks();
            }
        }
        
    
public static com.sun.xml.ws.rm.jaxws.runtime.client.RMSourcegetRMSource()

    
   
        
        return rmSource;
    
public longgetRetryInterval()

        return retryInterval;
    
public synchronized voidremoveOutboundSequence(ClientOutboundSequence seq)

        
         logger.fine(Messages.REMOVING_SEQUENCE_MESSAGE.format( seq.getId()));
         
         String id = seq.getId();
         
        ClientInboundSequence iseq = 
                    (ClientInboundSequence)seq.getInboundSequence();
            
        String iseqid = null;
        if (iseq != null && null != (iseqid = iseq.getId())) {
            inboundMap.remove(iseqid);
        }
        outboundMap.remove(id);
        
        if (outboundMap.isEmpty()) {
            retryTimer.stop();
        }
    
private voidremoveOutboundSequence(java.lang.String id)

        
         ClientOutboundSequence seq = outboundMap.get(id);
         
         if (seq != null) {
            removeOutboundSequence(seq);
         } else {
             String message = Messages.NO_SUCH_OUTBOUND_SEQUENCE.format(id);
             IllegalArgumentException e = new IllegalArgumentException(message);
             logger.log(Level.FINE, message, e);
             throw e;
         }
    
public voidsetRetryInterval(long retryInterval)

        this.retryInterval = retryInterval;
    
public synchronized voidterminateSequence(ClientOutboundSequence seq)

        
        String id = seq.getId();
        if (seq != null && outboundMap.keySet().contains(id)) {
            seq.disconnect();
            removeOutboundSequence(id);
        }