1 29 30 package com.caucho.server.cluster; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.Alarm; 34 import com.caucho.vfs.ReadStream; 35 import com.caucho.vfs.WriteStream; 36 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 40 43 public class ClusterStream { 44 static protected final Logger log = Log.open(ClusterStream.class); 45 46 private ClusterClient _srun; 47 48 private ReadStream _is; 49 private WriteStream _os; 50 51 private long _freeTime; 52 53 private String _debugId; 54 55 ClusterStream(int count, ClusterClient client, 56 ReadStream is, WriteStream os) 57 { 58 _srun = client; 59 _is = is; 60 _os = os; 61 62 _debugId = "[" + client.getDebugId() + ":" + count + "]"; 63 } 64 65 68 public ClusterClient getServer() 69 { 70 return _srun; 71 } 72 73 76 public ReadStream getReadStream() 77 { 78 return _is; 79 } 80 81 84 public WriteStream getWriteStream() 85 { 86 return _os; 87 } 88 89 92 public long getFreeTime() 93 { 94 return _freeTime; 95 } 96 97 100 public void setFreeTime(long freeTime) 101 { 102 _freeTime = freeTime; 103 } 104 105 108 public boolean isLongIdle() 109 { 110 return (_srun.getServer().getLoadBalanceIdleTime() < 111 Alarm.getCurrentTime() - _freeTime + 2000L); 112 } 113 114 117 public String getDebugId() 118 { 119 return _debugId; 120 } 121 122 125 public void clearRecycle() 126 { 127 _srun.clearRecycle(); 128 } 129 130 133 public void free() 134 { 135 if (_is != null) 136 _freeTime = _is.getReadTime(); 137 138 _srun.free(this); 139 } 140 141 public void close() 142 { 143 if (_is != null) 144 _srun.close(this); 145 146 closeImpl(); 147 } 148 149 152 void closeImpl() 153 { 154 ReadStream is = _is; 155 _is = null; 156 157 WriteStream os = _os; 158 _os = null; 159 160 try { 161 if (is != null) 162 is.close(); 163 } catch (Throwable e) { 164 log.log(Level.FINER, e.toString(), e); 165 } 166 167 try { 168 if (os != null) 169 os.close(); 170 } catch (Throwable e) { 171 log.log(Level.FINER, e.toString(), e); 172 } 173 } 174 } 175 | Popular Tags |