2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: SessionState.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.3 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 15:30:16 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.remote.gateway; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
15 |
import java.io.InputStream; |
2 |
26 Feb 07 |
jari |
16 |
import java.io.OutputStream; |
2 |
26 Feb 07 |
jari |
17 |
import java.io.PipedInputStream; |
2 |
26 Feb 07 |
jari |
18 |
import java.io.PipedOutputStream; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import org.tigr.remote.gateway.util.IQueue; |
2 |
26 Feb 07 |
jari |
21 |
import org.tigr.remote.gateway.util.Queue; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
class SessionState { |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
/** |
2 |
26 Feb 07 |
jari |
* Construct a <code>SessionState</code>. |
2 |
26 Feb 07 |
jari |
27 |
*/ |
2 |
26 Feb 07 |
jari |
28 |
public SessionState() { |
2 |
26 Feb 07 |
jari |
29 |
} |
2 |
26 Feb 07 |
jari |
30 |
|
2 |
26 Feb 07 |
jari |
31 |
/** |
2 |
26 Feb 07 |
jari |
* Connects wrapped pipe streams. |
2 |
26 Feb 07 |
jari |
33 |
*/ |
2 |
26 Feb 07 |
jari |
34 |
public void connect() throws IOException { |
2 |
26 Feb 07 |
jari |
35 |
m_out = new PipedOutputStream(); |
2 |
26 Feb 07 |
jari |
36 |
m_in = new PipedInputStream( m_out ); |
2 |
26 Feb 07 |
jari |
37 |
} |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if wrapped pipe streams are connected. |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public void checkConnected() { |
2 |
26 Feb 07 |
jari |
43 |
if (( m_out == null ) || ( m_in == null )) |
2 |
26 Feb 07 |
jari |
44 |
throw new NullPointerException("Program error: pipe streams are not connected"); |
2 |
26 Feb 07 |
jari |
45 |
} |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
/** |
2 |
26 Feb 07 |
jari |
* Clean up pipe streams. |
2 |
26 Feb 07 |
jari |
49 |
*/ |
2 |
26 Feb 07 |
jari |
50 |
public void free() { |
2 |
26 Feb 07 |
jari |
51 |
m_in = null; |
2 |
26 Feb 07 |
jari |
52 |
m_out = null; |
2 |
26 Feb 07 |
jari |
53 |
} |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a monitor for this session state. |
2 |
26 Feb 07 |
jari |
57 |
*/ |
2 |
26 Feb 07 |
jari |
58 |
public void createMonitor() throws IOException { |
2 |
26 Feb 07 |
jari |
59 |
if (m_monitor != false) |
2 |
26 Feb 07 |
jari |
60 |
throw new IOException("Sesion monitor exists"); |
2 |
26 Feb 07 |
jari |
61 |
m_monitor = true; |
2 |
26 Feb 07 |
jari |
62 |
} |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
/** |
2 |
26 Feb 07 |
jari |
* Releases a monitor for this session state. |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
public void releaseMonitor() { m_monitor = false;} |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if request for this session state is ready. |
2 |
26 Feb 07 |
jari |
71 |
*/ |
2 |
26 Feb 07 |
jari |
72 |
public boolean isLocked() { return m_monitor == true;} |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
public IQueue getMessageQueue() { return m_queue;} |
2 |
26 Feb 07 |
jari |
75 |
public IQueue getRequestQueue() { return m_requestQueue;} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
public InputStream getInputPipe() { return m_in;} |
2 |
26 Feb 07 |
jari |
78 |
public OutputStream getOutputPipe() { return m_out;} |
2 |
26 Feb 07 |
jari |
79 |
|
2 |
26 Feb 07 |
jari |
80 |
private PipedInputStream m_in; |
2 |
26 Feb 07 |
jari |
81 |
private PipedOutputStream m_out; |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
private IQueue m_queue = new Queue(); |
2 |
26 Feb 07 |
jari |
84 |
private IQueue m_requestQueue = new Queue(); |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
private boolean m_monitor = false; |
2 |
26 Feb 07 |
jari |
87 |
} |