title: How do I handle a single text io stream with multiple inputs and outputs?
body: <p>So I'm working through a bit of a problem, and some advice would be nice. First a little background, please excuse the length.</p>
  
  <p>I am working on a management system that queries network devices via the <a href="http://en.wikipedia.org/wiki/Transaction_Language_1" rel="nofollow noreferrer">TL1 protocol</a>.  For those unfamiliar with the protocol, the short answer is that is is a "human readable" language that communicates via a text based IO stream. </p>
  
  <p>I am using Spring and Jsch to open a port to the remote NE (network element), login, run the command, then close the connection.  There are two kinds of ways to get into the remote NE's, either directly (via the ssh gateway) <strong>if</strong> the element has a tcp/ip address (many are osi only), or through an ems (management system) of some type using what is called a "northbound interface".  </p>
  
  <p>Either way, the procedure is the same. </p>
  
  <ul>
  <li>Use Jsch to open a port to the NE or ems.    </li>
  <li>Send login command for the NE ex. <code>"act-user&lt;tid&gt;:&lt;username&gt;:UniqueId::&lt;password&gt;;"</code> </li>
  <li>Send command ex. <code>"rtrv-alm-all:&lt;tid&gt;:ALL:uniqueid::,,,,;"</code></li>
  <li><p>Retrieve and process results. The results of the above for example might look something like this...</p>
  
  <p><code>RTRV-ALM-ALL:foo:ALL:uniqueid;</code></p>
  
  <p><code>CMPSW205 02-01-11 18:33:05</code></p>
  
  <p><code>M uniqueid COMPLD</code></p>
  
  <p><code>"01-01-06:MJ,BOARDOUT-ALM,SA,01-10,12-53-58,,:\"OPA_C__LRX:BOARD EXTRACTED\","</code></p>
  
  <p><code>;</code></p></li>
  </ul>
  
  <p>The <code>;</code> is important because it signals the end of the response.</p>
  
  <ul>
  <li>Lastly logout, and close the port.</li>
  </ul>
  
  <p>With Spring I have been using the <code>ThreadPoolTaskExecutor</code> quite effectively to do this.</p>
  
  <p>Until this issue came up ...</p>
  
  <p>With one particular ems platform (Hitachi) I ran across a roadblock with my approach. This ems handles as many as 80 nodes through it.  You connect to the port, then issue a command to login to the ems, then run commands pointing to the various NE's.  Same procedure as before, but here is the problem...</p>
  
  <p>After you login into the ems, the next command, no matter what it is, <strong>will take up to 10 minutes to complete</strong>. until that happens, all other commands are blocked. After this initial wait all other commands work quickly. There appears to be no way to defeat this behaviour (my suspicion is that there is some NE auto-discovery happening during this period).</p>
  
  <p>Now the thrust of my question...</p>
  
  <p>So my next approach for this platform would be to connect to the ems, login to it, and keep the connection open, and just pass commands to the various NE's.  That would mean a 10 minute delay after the application (web based) first loads, but would be fine after this point.</p>
  
  <p>The problem I have is how best to do this.  Having a single text based iostream for passing this stuff through looks like a large bottleneck, plus multiple users will be using the application, how do I handle multiple commands and responses against this single iostream? I can open a few iostreams (maybe up to 6) on this ems, but that also complicates sorting out what goes where.  </p>
  
  <p>Any advice on direction would be appreciated.   </p>