View Javadoc

1   /*
2    * $Id: StreamConnector.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.stream;
12  
13  import org.mule.providers.AbstractConnector;
14  import org.mule.providers.AbstractPollingMessageReceiver;
15  import org.mule.umo.UMOComponent;
16  import org.mule.umo.endpoint.UMOEndpoint;
17  import org.mule.umo.provider.UMOMessageReceiver;
18  
19  import java.io.InputStream;
20  import java.io.OutputStream;
21  
22  import org.apache.commons.io.IOUtils;
23  
24  /**
25   * <code>StreamConnector</code> can send and receive Mule events over IO streams.
26   */
27  
28  public abstract class StreamConnector extends AbstractConnector
29  {
30      public static final String STREAM_SYSTEM_IN = "system.in";
31      public static final String STREAM_SYSTEM_OUT = "system.out";
32      public static final String STREAM_SYSTEM_ERR = "system.err";
33  
34      protected OutputStream outputStream;
35      protected InputStream inputStream;
36  
37      /*
38       * (non-Javadoc)
39       * 
40       * @see org.mule.umo.provider.UMOConnector#registerListener(org.mule.umo.UMOSession,
41       *      org.mule.umo.endpoint.UMOEndpoint)
42       */
43      public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception
44      {
45          return serviceDescriptor.createMessageReceiver(this, component, endpoint,
46              new Object[]{new Long(AbstractPollingMessageReceiver.DEFAULT_POLL_FREQUENCY)});
47      }
48  
49      /*
50       * (non-Javadoc)
51       * 
52       * @see org.mule.providers.AbstractConnector#doStop()
53       */
54      public void doStop()
55      {
56          // template method
57      }
58  
59      protected void doDispose()
60      {
61          IOUtils.closeQuietly(inputStream);
62          IOUtils.closeQuietly(outputStream);
63      }
64  
65      /*
66       * (non-Javadoc)
67       * 
68       * @see org.mule.providers.AbstractConnector#doStart()
69       */
70      public void doStart()
71      {
72          // template method
73      }
74  
75      /*
76       * (non-Javadoc)
77       * 
78       * @see org.mule.umo.provider.UMOConnector#getProtocol()
79       */
80  
81      public String getProtocol()
82      {
83          return "stream";
84      }
85  
86      public InputStream getInputStream()
87      {
88          return inputStream;
89      }
90  
91      public void setInputStream(InputStream inputStream)
92      {
93          this.inputStream = inputStream;
94      }
95  
96      public OutputStream getOutputStream()
97      {
98          return outputStream;
99      }
100 
101     public void setOutputStream(OutputStream outputStream)
102     {
103         this.outputStream = outputStream;
104     }
105 
106 }