Пример #1
0
    public Builder(
        Operator key,
        Connectionable connection,
        MessageProcessable messageProcess,
        HeartbeatKeepable heartbeatKeep) {

      _key = key;
      _connection = connection;
      _messageProcess = messageProcess;
      _heartbeatKeep = heartbeatKeep;
      _generatorSeq = new MemoryGeneratorSeq(_key.getCompanyId(), _key.getCompanyId());
    }
Пример #2
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((_key == null) ? 0 : _key.hashCode());
   return result;
 }
Пример #3
0
 /**
  * 链接服务端开始服务
  *
  * @throws ClientException
  */
 @Override
 public void start() throws IOException {
   synchronized (_monitor) {
     if (isNew()) {
       logger.debug("{} Session is start", _key.toString());
       try {
         _status = Status.Active;
         _channel = _conn.connect(this);
       } catch (IOException e) {
         logger.error("{} Session start is fail,error is {}", _key.toString(), e.getMessage());
         _status = Status.Close;
         throw e;
       }
     }
   }
 }
Пример #4
0
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("OperatorChannel [_operatorKey=");
   builder.append(_key.toString());
   builder.append("]");
   return builder.toString();
 }
Пример #5
0
 private void logout() {
   try {
     LogoutRequest r = new LogoutRequest();
     send(r);
   } catch (IOException e) {
     logger.error("{} send logout", _key.toString());
   }
 }
Пример #6
0
 @Override
 public void heartbeatTouch() {
   _lastHeartbeanTime = System.currentTimeMillis();
   try {
     if (isClientRquestTimeout()) {
       logger.debug("{} client request timeout close session", _key.toString());
       close();
     }
   } catch (IOException e) {
     logger.error("Client request timeout close error {}", e.toString());
   }
 }
Пример #7
0
  @Override
  public void close() throws IOException {
    synchronized (_monitor) {
      if (isClose()) {
        return;
      }

      if (isNew()) {
        _status = Status.Close;
        return;
      }

      logger.debug("{} start session close", _key.toString());
      logout();
      _status = Status.Close;
      _heartbeatKeep.shutdown();
      if (_channel != null && _channel.isOpen()) {
        _channel.close();
      }
      logger.debug("{} finish session close", _key.toString());
    }
  }
Пример #8
0
  @Override
  public void send(Requestable<? extends Response> request) throws IOException {
    synchronized (_monitor) {
      if (isNew()) {
        start();
      }
    }

    if (isClose()) {
      logger.debug("{} Send message,but closed", _key.toString());
      throw new IOException("Session already closed,not send message.");
    }
    if (isAccess(request.getMessageType())) {
      _messageProcess.sendProcess(this, request, _generator);
      if (isRequestMessage(request.getMessageType())) {
        _lastClientRequestTime = System.currentTimeMillis();
        heartbeatTouch();
      }
    } else {
      logger.debug("{} not access cti server.", _key.toString());
      throw new SessionAccessException(_key);
    }
  }
Пример #9
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   Session other = (Session) obj;
   if (_key == null) {
     if (other._key != null) {
       return false;
     }
   } else if (!_key.equals(other._key)) {
     return false;
   }
   return true;
 }