/**
  * Calculates the connectionState resulting from the message in the current connection state.
  * Checks if the specified message is allowed in the connection's state and throws an exception if
  * not.
  *
  * @param con
  * @param msg
  * @return
  * @throws won.protocol.exception.IllegalMessageForConnectionStateException if the message is not
  *     allowed in the connection's current state
  */
 private ConnectionState performStateTransit(Connection con, ConnectionEventType msg)
     throws IllegalMessageForConnectionStateException {
   if (!msg.isMessageAllowed(con.getState())) {
     throw new IllegalMessageForConnectionStateException(
         con.getConnectionURI(), msg.name(), con.getState());
   }
   return con.getState().transit(msg);
 }
 private void handleKeepAlive() {
   Connection c = null;
   try {
     netCode = ois.readInt();
     c = checkConnectionNetCode();
     if (c != null && c.getState() == Connection.STATE_CONNECTED) {
       oos.writeInt(ACK_KEEP_ALIVE);
       oos.flush();
       System.out.println("->ACK_KEEP_ALIVE"); // $NON-NLS-1$
     } else {
       System.out.println("->NOT_CONNECTED"); // $NON-NLS-1$
       oos.writeInt(NOT_CONNECTED);
       oos.flush();
     }
   } catch (IOException e) {
     System.out.println("handleKeepAlive: " + e.getMessage()); // $NON-NLS-1$
     if (c != null) {
       c.setState(Connection.STATE_DISCONNECTED);
       System.out.println(
           "Connection closed with "
               + c.getRemoteAddress()
               + //$NON-NLS-1$
               ":"
               + c.getRemotePort()); // $NON-NLS-1$
     }
   }
 }
Пример #3
0
  /**
   * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
   * connection.
   *
   * @param phoneAccountHandle The phone account handle for the connection.
   * @param connection The connection to add.
   */
  public final void addExistingConnection(
      PhoneAccountHandle phoneAccountHandle, Connection connection) {

    String id = addExistingConnectionInternal(connection);
    if (id != null) {
      List<String> emptyList = new ArrayList<>(0);

      ParcelableConnection parcelableConnection =
          new ParcelableConnection(
              phoneAccountHandle,
              connection.getState(),
              connection.getConnectionCapabilities(),
              connection.getAddress(),
              connection.getAddressPresentation(),
              connection.getCallerDisplayName(),
              connection.getCallerDisplayNamePresentation(),
              connection.getVideoProvider() == null
                  ? null
                  : connection.getVideoProvider().getInterface(),
              connection.getVideoState(),
              connection.isRingbackRequested(),
              connection.getAudioModeIsVoip(),
              connection.getStatusHints(),
              connection.getDisconnectCause(),
              emptyList);
      mAdapter.addExistingConnection(id, parcelableConnection);
    }
  }
Пример #4
0
 public boolean doesUserExist(String newUser) {
   boolean result = false;
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       result = clientThread.getUserName().compareTo(newUser) == 0;
     }
   }
   return result;
 }
Пример #5
0
 public ArrayList<String> getUserList() {
   ArrayList<String> userList = new ArrayList<String>();
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       userList.add(clientThread.getUserName());
     }
   }
   return userList;
 }
Пример #6
0
 public boolean sendPrivateMessage(String message, String user) {
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       if (clientThread.getUserName().compareTo(user) == 0) {
         clientThread.messageForConnection(message + System.lineSeparator());
         return true;
       }
     }
   }
   return false;
 }
  public Connection getConnection(
      List<Connection> connections, URI facetURI, ConnectionEventType eventType)
      throws ConnectionAlreadyExistsException {
    Connection con = null;

    for (Connection c : connections) {
      // TODO: check remote need type as well or create GroupMemberFacet
      if (facetURI.equals(c.getTypeURI())) con = c;
    }

    /**
     * check if there already exists a connection between those two we have multiple options: a) no
     * connection exists -> create new b) a connection exists in state CONNECTED -> error message c)
     * a connection exists in state REQUEST_SENT. The call must be a duplicate (or re-sent after the
     * remote end hasn't replied for some time) -> error message d) a connection exists in state
     * REQUEST_RECEIVED. The remote end tried to connect before we did. -> error message e) a
     * connection exists in state CLOSED -> create new
     */

    // TODO: impose unique constraint on connections
    if (con != null) {
      if (con.getState() == ConnectionState.CONNECTED
          || con.getState() == ConnectionState.REQUEST_SENT)
        throw new ConnectionAlreadyExistsException(
            con.getConnectionURI(), con.getNeedURI(), con.getRemoteNeedURI());
      /*if(!eventType.isMessageAllowed(con.getState())){
        throw new ConnectionAlreadyExistsException(con.getConnectionURI(), con.getNeedURI(), con.getRemoteNeedURI());
      }*/ else {
        // TODO: Move this to the transition() - Method in ConnectionState
        con.setState(con.getState().transit(eventType));
        con = connectionRepository.saveAndFlush(con);
      }
    }

    return con;
  }
  private void handleSendCode() {
    Connection c = null;
    GeneticCode code;

    try {
      netCode = ois.readInt();
      c = checkConnectionNetCode();
      if (c != null && c.getState() == Connection.STATE_CONNECTED) {
        oos.writeInt(WAITING_CODE);
        oos.flush();
        System.out.println("->WAITING_CODE"); // $NON-NLS-1$
        code = (GeneticCode) ois.readObject();
        System.out.println("Genetic code"); // $NON-NLS-1$
        oos.writeInt(CODE_RECEIVED);
        oos.flush();
        System.out.println("->CODE_RECEIVED"); // $NON-NLS-1$
        c.getInCorridor().receiveOrganism(code);
      } else {
        System.out.println("->NOT_CONNECTED"); // $NON-NLS-1$
        oos.writeInt(NOT_CONNECTED);
        oos.flush();
      }
    } catch (IOException e) {
      System.out.println("handleSendCode: " + e.getMessage()); // $NON-NLS-1$
      if (c != null) {
        c.setState(Connection.STATE_DISCONNECTED);
        System.out.println(
            "Connection closed with "
                + c.getRemoteAddress()
                + //$NON-NLS-1$
                ":"
                + c.getRemotePort()); // $NON-NLS-1$
      }
    } catch (ClassNotFoundException e) {
      System.out.println("handleSendCode: " + e.getMessage()); // $NON-NLS-1$
      if (c != null) {
        c.setState(Connection.STATE_DISCONNECTED);
        System.out.println(
            "Connection closed with "
                + c.getRemoteAddress()
                + //$NON-NLS-1$
                ":"
                + c.getRemotePort()); // $NON-NLS-1$
      }
    }
  }
  @Override
  public void update(Connection c) {
    int state = c.getState();
    World w = currentWorld.getWorld();

    if (state == Connection.STATE_DISCONNECTED) {
      notifyStatusListeners(
          Messages.getInstance()
              .getString("T_CONNECTION_LOST", c.getRemoteAddress().toString())); // $NON-NLS-1$
      w.removeAgent(c.getInCorridor());
      w.removeAgent(c.getOutCorridor());
      removeConnection(c);
    } else if (state == Connection.STATE_CONNECTED) {
      w.addAgent(c.getInCorridor(), null);
      w.addAgent(c.getOutCorridor(), null);
      notifyStatusListeners(
          Messages.getInstance()
              .getString(
                  "T_CONNECTION_STABLISHED", c.getRemoteAddress().toString())); // $NON-NLS-1$
    }
  }
Пример #10
0
  /**
   * This can be used by telecom to either create a new outgoing call or attach to an existing
   * incoming call. In either case, telecom will cycle through a set of services and call
   * createConnection util a connection service cancels the process or completes it successfully.
   */
  private void createConnection(
      final PhoneAccountHandle callManagerAccount,
      final String callId,
      final ConnectionRequest request,
      boolean isIncoming,
      boolean isUnknown) {
    Log.d(
        this,
        "createConnection, callManagerAccount: %s, callId: %s, request: %s, "
            + "isIncoming: %b, isUnknown: %b",
        callManagerAccount,
        callId,
        request,
        isIncoming,
        isUnknown);

    Connection connection =
        isUnknown
            ? onCreateUnknownConnection(callManagerAccount, request)
            : isIncoming
                ? onCreateIncomingConnection(callManagerAccount, request)
                : onCreateOutgoingConnection(callManagerAccount, request);
    Log.d(this, "createConnection, connection: %s", connection);
    if (connection == null) {
      connection = Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR));
    }

    if (connection.getState() != Connection.STATE_DISCONNECTED) {
      addConnection(callId, connection);
    }

    Uri address = connection.getAddress();
    String number = address == null ? "null" : address.getSchemeSpecificPart();
    Log.v(
        this,
        "createConnection, number: %s, state: %s, capabilities: %s",
        Connection.toLogSafePhoneNumber(number),
        Connection.stateToString(connection.getState()),
        Connection.capabilitiesToString(connection.getConnectionCapabilities()));

    Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
    mAdapter.handleCreateConnectionComplete(
        callId,
        request,
        new ParcelableConnection(
            request.getAccountHandle(),
            connection.getState(),
            connection.getConnectionCapabilities(),
            connection.getAddress(),
            connection.getAddressPresentation(),
            connection.getCallerDisplayName(),
            connection.getCallerDisplayNamePresentation(),
            connection.getVideoProvider() == null
                ? null
                : connection.getVideoProvider().getInterface(),
            connection.getVideoState(),
            connection.isRingbackRequested(),
            connection.getAudioModeIsVoip(),
            connection.getStatusHints(),
            connection.getDisconnectCause(),
            createIdList(connection.getConferenceables())));
  }