1
2
3
4
5
6
7 package org.mule.transport.stdio;
8
9 import org.mule.api.MuleContext;
10 import org.mule.api.construct.FlowConstruct;
11 import org.mule.api.endpoint.InboundEndpoint;
12 import org.mule.api.processor.MessageProcessor;
13 import org.mule.api.transport.MessageReceiver;
14 import org.mule.transport.AbstractConnector;
15 import org.mule.transport.AbstractPollingMessageReceiver;
16
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 import org.apache.commons.io.IOUtils;
21
22
23
24
25
26 public abstract class StdioConnector extends AbstractConnector
27 {
28
29 public static final String STDIO = "stdio";
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 public StdioConnector(MuleContext context)
38 {
39 super(context);
40 }
41
42 @Override
43 public MessageReceiver createReceiver(FlowConstruct flowConstruct, InboundEndpoint endpoint) throws Exception
44 {
45 return serviceDescriptor.createMessageReceiver(this, flowConstruct, endpoint,
46 AbstractPollingMessageReceiver.DEFAULT_POLL_FREQUENCY);
47 }
48
49 @Override
50 public void doStop()
51 {
52
53 }
54
55 @Override
56 protected void doDispose()
57 {
58 IOUtils.closeQuietly(inputStream);
59 IOUtils.closeQuietly(outputStream);
60 }
61
62 @Override
63 public void doStart()
64 {
65
66 }
67
68 public String getProtocol()
69 {
70 return STDIO;
71 }
72
73 public InputStream getInputStream()
74 {
75 return inputStream;
76 }
77
78 public void setInputStream(InputStream inputStream)
79 {
80 this.inputStream = inputStream;
81 }
82
83 public OutputStream getOutputStream()
84 {
85 return outputStream;
86 }
87
88 public void setOutputStream(OutputStream outputStream)
89 {
90 this.outputStream = outputStream;
91 }
92
93 public void registerListener(InboundEndpoint endpoint, MessageProcessor listener, FlowConstruct flowConstruct) throws Exception
94 {
95 if (receivers.size() > 0)
96 {
97 throw new UnsupportedOperationException(
98 "You can only register one listener per system stream connector");
99 }
100 super.registerListener(endpoint, listener, flowConstruct);
101 }
102 }