01: // @(#)ReaderWriter.java 1.11 "@(#)ReaderWriter.java 1.11 99/09/23 Sun Microsystems"
02:
03: package com.sun.portal.netlet.econnection;
04:
05: import java.io.DataInputStream;
06: import java.io.DataOutputStream;
07: import java.io.InputStream;
08: import java.io.OutputStream;
09:
10: public abstract class ReaderWriter implements Runnable {
11: protected ReaderWriterLock rwLock;
12:
13: protected DataInputStream in;
14:
15: protected DataOutputStream out;
16:
17: final protected int MAXBUFFERSIZE = 8 * 1024;
18:
19: protected boolean sent = false;
20:
21: protected volatile boolean go = true;
22:
23: protected int message_type = -1;
24:
25: public ReaderWriter(ReaderWriterLock l, InputStream inStream,
26: OutputStream outStream) {
27: rwLock = l;
28: in = new DataInputStream(inStream);
29: out = new DataOutputStream(outStream);
30: }
31:
32: public abstract void run();
33:
34: /*
35: * Added for RFE 4492648
36: */
37:
38: public abstract long getLastActivityTime();
39:
40: void clean() {
41: if (in != null) {
42: try {
43: in.close();
44: } catch (Exception e) {
45: } finally {
46: in = null;
47: }
48: }
49:
50: if (out != null) {
51: try {
52: out.close();
53: } catch (Exception e) {
54: } finally {
55: out = null;
56: }
57: }
58: }
59:
60: public void setMessageType(int mesgType) {
61: message_type = mesgType;
62: }
63:
64: public int getMessageType() {
65: return message_type;
66: }
67:
68: public void netletstop() {
69: go = false;
70: clean();
71: }
72:
73: public void stop() {
74: go = false;
75: clean();
76: }
77:
78: public boolean sentDataFlag() {
79: return (sent);
80: }
81:
82: public void clearDataFlag() {
83: sent = false;
84: }
85:
86: public boolean isAlive() {
87: return (go);
88: }
89: }
|