private void testRaiseEvent() {
   printSomething("Start event test");
   FermatEvent eventToRaise =
       eventManager.getNewEvent(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION);
   eventToRaise.setSource(EventSource.NETWORK_SERVICE_ASSET_TRANSMISSION);
   eventManager.raiseEvent(eventToRaise);
   printSomething("End event test");
 }
 private void testRaiseEvent() {
   printSomething("Start event test");
   FermatEvent eventToRaise =
       eventManager.getNewEvent(
           EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER);
   eventToRaise.setSource(EventSource.CRYPTO_ROUTER);
   eventManager.raiseEvent(eventToRaise);
   printSomething("End event test");
 }
  /** Notify when cloud client is disconnected */
  public void raiseClientConnectionLooseNotificationEvent() {

    System.out.println(
        "WsCommunicationsTyrusCloudClientChannel - raiseClientConnectionLooseNotificationEvent");
    FermatEvent platformEvent = eventManager.getNewEvent(P2pEventType.CLIENT_CONNECTION_LOOSE);
    platformEvent.setSource(EventSource.WS_COMMUNICATION_CLOUD_CLIENT_PLUGIN);
    eventManager.raiseEvent(platformEvent);
    System.out.println(
        "WsCommunicationsTyrusCloudClientChannel - Raised Event = P2pEventType.CLIENT_CONNECTION_LOOSE");
  }
  /**
   * Notify when cloud client component es registered, this event is raise to show the message in a
   * popup of the UI
   */
  public void riseCompleteClientComponentRegistrationNotificationEvent() {

    FermatEvent platformEvent =
        eventManager.getNewEvent(P2pEventType.COMPLETE_CLIENT_COMPONENT_REGISTRATION_NOTIFICATION);
    CompleteClientComponentRegistrationNotificationEvent event =
        (CompleteClientComponentRegistrationNotificationEvent) platformEvent;
    event.setSource(EventSource.WS_COMMUNICATION_CLOUD_CLIENT_PLUGIN);
    event.setMessage("Cloud client communication, registered and established connection.");
    eventManager.raiseEvent(platformEvent);
  }
  @Override
  public void start() throws CantStartPluginException {

    try {

      FermatEventListener fermatEventListener;
      FermatEventHandler fermatEventHandler;

      this.cryptoCustomerActorDao =
          new CryptoCustomerActorDao(pluginDatabaseSystem, pluginFileSystem, pluginId);
      this.cryptoCustomerActorDao.initializeDatabase();

      fermatManager =
          new CustomerActorManager(
              this.cryptoCustomerActorDao,
              cryptoBrokerANSManager,
              errorManager,
              getPluginVersionReference());

      ActorCustomerExtraDataEventActions handlerAction =
          new ActorCustomerExtraDataEventActions(
              cryptoBrokerANSManager, cryptoCustomerActorDao, cryptoBrokerActorConnectionManager);

      fermatEventListener =
          eventManager.getNewListener(EventType.CRYPTO_BROKER_QUOTES_REQUEST_UPDATES);
      fermatEventHandler = new CryptoCustomerExtraDataEventHandler(handlerAction, this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      fermatEventListener =
          eventManager.getNewListener(EventType.CRYPTO_BROKER_ACTOR_CONNECTION_NEW_CONNECTION);
      fermatEventHandler = new CryptoBrokerNewConnectionEventHandler(handlerAction, this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      agente =
          new CryptoBrokerExtraDataUpdateAgent(
              cryptoBrokerANSManager,
              cryptoCustomerActorDao,
              errorManager,
              getPluginVersionReference());
      agente.start();
      this.serviceStatus = ServiceStatus.STARTED;

    } catch (CantStartAgentException | CantInitializeCryptoCustomerActorDatabaseException e) {
      errorManager.reportUnexpectedPluginException(
          this.getPluginVersionReference(),
          UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
          e);
      throw new CantStartPluginException(e, this.getPluginVersionReference());
    }
  }
  private void setUpMockitoRules() throws Exception {

    when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
    when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabase.getTable(
            AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_TABLE_NAME))
        .thenReturn(mockDatabaseTable);
    when(mockDatabase.getTable(
            AssetIssuingTransactionDatabaseConstants
                .DIGITAL_ASSET_TRANSACTION_ASSET_ISSUING_TABLE_NAME))
        .thenReturn(mockDatabaseTable2);
    when(mockDatabaseTable2.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabaseTable2.getRecords()).thenReturn(records);
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_DATABASE))
        .thenReturn(mockDatabase);

    when(deviceUser.getPublicKey()).thenReturn("myPublicKey");
    when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser);

    when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer);

    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener1);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener2);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener3);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener4);

    when(pluginFileSystem.createTextFile(
            this.pluginId,
            "digital-asset-issuing/publicKey",
            "name.xml",
            FilePrivacy.PUBLIC,
            FileLifeSpan.PERMANENT))
        .thenReturn(pluginTextFile);
    when(bitcoinWalletManager.loadWallet(this.walletPublicKey)).thenReturn(bitcoinWalletWallet);
    when(bitcoinWalletWallet.getBalance(BalanceType.AVAILABLE)).thenReturn(bitcoinWalletBalance);
    when(bitcoinWalletBalance.getBalance()).thenReturn(bitcoinWalletAvailableBalance);
    when(assetVaultManager.getNewAssetVaultCryptoAddress(this.blockchainNetworkType))
        .thenReturn(cryptoAddress);
    //        doNothing().when(assetIssuingPluginRoot).issueAssets(digitalAsset, 1, walletPublicKey,
    // blockchainNetworkType);
  }
  @Override
  public void start() throws CantStartServiceException {
    try {
      /** I will initialize the handling of com.bitdubai.platform events. */
      FermatEventListener fermatEventListener;
      FermatEventHandler fermatEventHandler;

      fermatEventListener =
          eventManager.getNewListener(EventType.INCOMING_NEW_CONTRACT_STATUS_UPDATE);
      fermatEventHandler = new IncomingNewContractStatusUpdateEventHandler();
      ((IncomingNewContractStatusUpdateEventHandler) fermatEventHandler)
          .setBrokerSubmitOfflineMerchandiseRecorderService(this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      fermatEventListener =
          eventManager.getNewListener(EventType.INCOMING_CONFIRM_BUSINESS_TRANSACTION_RESPONSE);
      fermatEventHandler = new IncomingConfirmBusinessTransactionResponseEventHandler();
      ((IncomingConfirmBusinessTransactionResponseEventHandler) fermatEventHandler)
          .setBrokerSubmitOfflineMerchandiseRecorderService(this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      this.serviceStatus = ServiceStatus.STARTED;
    } catch (CantSetObjectException exception) {
      this.errorManager.reportUnexpectedPluginException(
          Plugins.BROKER_SUBMIT_OFFLINE_MERCHANDISE,
          UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
          exception);
      throw new CantStartServiceException(
          exception,
          "Starting the BrokerSubmitOfflineMerchandiseRecorderService",
          "The BrokerSubmitOfflineMerchandiseRecorderService is probably null");
    } catch (Exception exception) {
      this.errorManager.reportUnexpectedPluginException(
          Plugins.BROKER_SUBMIT_OFFLINE_MERCHANDISE,
          UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
          exception);
      throw new CantStartServiceException(
          CantStartServiceException.DEFAULT_MESSAGE,
          exception,
          "Starting the CustomerOnlinePaymentRecorderService",
          "Unexpected error");
    }
  }
 private void receiveMessageTest() {
   try {
     /**
      * This test must be finish in an exception, because the network service mock is not created.
      * The objective in this method is raise the incoming chat and handle this event. This
      * exception must be thrown in chat monitor agent.
      */
     FermatEvent fermatEvent = eventManager.getNewEvent(EventType.INCOMING_CHAT);
     IncomingChat incomingChat = (IncomingChat) fermatEvent;
     incomingChat.setSource(EventSource.NETWORK_SERVICE_CHAT);
     incomingChat.setChatId(UUID.fromString("52d7fab8-a423-458f-bcc9-49cdb3e9ba8f"));
     eventManager.raiseEvent(incomingChat);
   } catch (Exception exception) {
     System.out.println(
         "Exception in raise event chat middleware test: " + exception.getMessage());
     exception.printStackTrace();
   }
 }
  /**
   * Notify the client when a incoming message is receive by the
   * incomingTemplateNetworkServiceMessage ant fire a new event
   *
   * @param incomingMessage received
   */
  private void onMessageReceived(FermatMessage incomingMessage) {

    System.out.println("CommunicationNetworkServiceLocal - onMessageReceived ");
    System.out.println(incomingMessage.getContent());

    /*
     * set the last message received
     */
    this.lastMessageReceived = incomingMessage;

    /** Put the message on a event and fire new event */
    FermatEvent fermatEvent =
        eventManager.getNewEvent(P2pEventType.NEW_NETWORK_SERVICE_MESSAGE_RECEIVE_NOTIFICATION);
    fermatEvent.setSource(AssetTransmissionNetworkServicePluginRoot.EVENT_SOURCE);
    ((NewNetworkServiceMessageReceivedNotificationEvent) fermatEvent).setData(incomingMessage);
    ((NewNetworkServiceMessageReceivedNotificationEvent) fermatEvent)
        .setNetworkServiceTypeApplicant(networkServiceTypePluginRoot);
    eventManager.raiseEvent(fermatEvent);
  }
  @Override
  public void stop() {
    super.stop();
    for (FermatEventListener fermatEventListener : listenersAdded) {
      eventManager.removeListener(fermatEventListener);
    }
    listenersAdded.clear();

    agente.stop();
  }
  @Override
  public void stop() {

    /** I will remove all the event listeners registered with the event manager. */
    for (FermatEventListener fermatEventListener : listenersAdded) {
      eventManager.removeListener(fermatEventListener);
    }

    listenersAdded.clear();
    this.serviceStatus = ServiceStatus.STOPPED;
  }
  private void setUpEventListeners() {

    FermatEventListener fermatEventListenerNewNotification =
        eventManager.getNewListener(EventType.INCOMING_MONEY_NOTIFICATION);
    FermatEventHandler fermatEventHandlerNewNotification =
        new IncomingMoneyNotificationHandler(this);
    fermatEventListenerNewNotification.setEventHandler(fermatEventHandlerNewNotification);
    eventManager.addListener(fermatEventListenerNewNotification);
    listenersAdded.add(fermatEventListenerNewNotification);

    FermatEventListener fermatEventListenerCloudClientConnectedNotification =
        eventManager.getNewListener(
            P2pEventType.COMPLETE_CLIENT_COMPONENT_REGISTRATION_NOTIFICATION);
    FermatEventHandler CloudClietNotificationHandler =
        new com.bitdubai.fermat_pip_plugin.layer.sub_app_module.notification.developer.bitdubai
            .version_1.event_handlers.CloudClietNotificationHandler(this);
    fermatEventListenerCloudClientConnectedNotification.setEventHandler(
        CloudClietNotificationHandler);
    eventManager.addListener(fermatEventListenerCloudClientConnectedNotification);
    listenersAdded.add(fermatEventListenerCloudClientConnectedNotification);

    FermatEventListener fermatEventListenerIncomingRequestConnectionNotification =
        eventManager.getNewListener(
            EventType.INCOMING_INTRA_ACTOR_REQUUEST_CONNECTION_NOTIFICATION);
    FermatEventHandler incomingRequestConnectionNotificationHandler =
        new com.bitdubai.fermat_pip_plugin.layer.sub_app_module.notification.developer.bitdubai
            .version_1.event_handlers.IncomingRequestConnectionNotificationHandler(this);
    fermatEventListenerIncomingRequestConnectionNotification.setEventHandler(
        incomingRequestConnectionNotificationHandler);
    eventManager.addListener(fermatEventListenerIncomingRequestConnectionNotification);
    listenersAdded.add(fermatEventListenerIncomingRequestConnectionNotification);
  }
  /**
   * (non-Javadoc)
   *
   * @see Service#stop()
   */
  @Override
  public void stop() {

    /*
     * Remove all the event listeners registered with the event manager.
     */
    for (FermatEventListener fermatEventListener : listenersAdded) {
      eventManager.removeListener(fermatEventListener);
    }

    /*
     * Clear the list
     */
    listenersAdded.clear();

    /*
     * Change the estatus
     */
    this.serviceStatus = ServiceStatus.STOPPED;
  }
  @Override
  public void stop() {

    // remove all listeners from the event manager and from the plugin.
    for (FermatEventListener listener : listenersAdded) eventManager.removeListener(listener);

    listenersAdded.clear();

    // close all connections.
    communicationNetworkServiceConnectionManager.closeAllConnection();

    // interrupt the registration agent execution
    communicationRegistrationProcessNetworkServiceAgent.stop();

    // interrupt the executor agent execution
    cryptoPaymentRequestExecutorAgent.stop();

    // set to not registered.
    register = Boolean.FALSE;

    this.serviceStatus = ServiceStatus.STOPPED;
  }
Exemple #15
0
  @Before
  public void setUp() throws Exception {
    subAppResourcesNetworkServicePluginRoot = new SubAppResourcesNetworkServicePluginRoot();
    subAppResourcesNetworkServicePluginRoot.setPluginFileSystem(pluginFileSystem);
    subAppResourcesNetworkServicePluginRoot.setEventManager(mockEventManager);
    subAppResourcesNetworkServicePluginRoot.setErrorManager(errorManager);
    subAppResourcesNetworkServicePluginRoot.setPluginDatabaseSystem(mockPluginDatabaseSystem);

    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenReturn(mockDatabase);
    when(gitHubConnection.getFile(anyString())).thenReturn(repoManifest);
    when(pluginFileSystem.createTextFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(layoutFile);
    when(pluginFileSystem.createBinaryFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(imageFile);

    when(mockEventManager.getNewListener(EventType.BEGUN_WALLET_INSTALLATION))
        .thenReturn(mockFermatEventListener);
    when(pluginFileSystem.getTextFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(mockPluginTextFile);
    setUpDataBase();
  }
  @Override
  public void start() throws CantStartServiceException {
    try {
      /** I will initialize the handling of com.bitdubai.platform events. */
      FermatEventListener fermatEventListener;
      FermatEventHandler fermatEventHandler;

      fermatEventListener = eventManager.getNewListener(EventType.INCOMING_CHAT);
      fermatEventHandler = new IncomingChatEventHandler();
      ((IncomingChatEventHandler) fermatEventHandler).setChatMiddlewareRecorderService(this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      fermatEventListener = eventManager.getNewListener(EventType.OUTGOING_CHAT);
      fermatEventHandler = new OutgoingChatEventHandler();
      ((OutgoingChatEventHandler) fermatEventHandler).setChatMiddlewareRecorderService(this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      fermatEventListener = eventManager.getNewListener(EventType.INCOMING_STATUS);
      fermatEventHandler = new IncomingNewChatStatusUpdateEventHandler();
      ((IncomingNewChatStatusUpdateEventHandler) fermatEventHandler)
          .setChatMiddlewareRecorderService(this);
      fermatEventListener.setEventHandler(fermatEventHandler);
      eventManager.addListener(fermatEventListener);
      listenersAdded.add(fermatEventListener);

      this.serviceStatus = ServiceStatus.STARTED;
    } catch (CantSetObjectException exception) {
      throw new CantStartServiceException(
          exception,
          "Starting the ChatMiddlewareRecorderService",
          "The ChatMiddlewareRecorderService is probably null");
    } catch (Exception exception) {
      errorManager.reportUnexpectedPluginException(
          Plugins.CHAT_MIDDLEWARE,
          UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
          FermatException.wrapException(exception));
      throw new CantStartServiceException(
          exception, "Starting the ChatMiddlewareRecorderService", "Unexpected Exception");
    }
  }
  /**
   * This method read for new messages pending to send on the data base in the table <code>
   * outbox_messages</code> and encrypt the message content, sing the message and send it
   */
  public void processMessageToSend() {

    try {

      try {

        Map<String, Object> filters = new HashMap<>();
        filters.put(
            CommunicationNetworkServiceDatabaseConstants.OUTGOING_MESSAGES_STATUS_COLUMN_NAME,
            MessagesStatus.PENDING_TO_SEND.getCode());
        filters.put(
            CommunicationNetworkServiceDatabaseConstants.OUTGOING_MESSAGES_RECEIVER_ID_COLUMN_NAME,
            communicationsVPNConnection.getRemoteParticipant().getIdentityPublicKey());

        /*
         * Read all pending message from database
         */
        List<FermatMessage> messages = outgoingMessageDao.findAll(filters);
        /*
         * For each message
         */
        for (FermatMessage message : messages) {

          if (communicationsVPNConnection.isActive()
              && (message.getFermatMessagesStatus() != FermatMessagesStatus.SENT)) {

            /*
             * Encrypt the content of the message whit the remote network service public key
             */
            ((FermatMessageCommunication) message)
                .setContent(
                    AsymmetricCryptography.encryptMessagePublicKey(
                        message.getContent(),
                        communicationsVPNConnection
                            .getRemoteParticipantNetworkService()
                            .getIdentityPublicKey()));

            /*
             * Sing the message
             */
            String signature =
                AsymmetricCryptography.createMessageSignature(
                    message.getContent(), eccKeyPair.getPrivateKey());
            ((FermatMessageCommunication) message).setSignature(signature);

            /*
             * Send the message
             */
            communicationsVPNConnection.sendMessage(message);

            /*
             * Change the message and update in the data base
             */

            ((FermatMessageCommunication) message)
                .setFermatMessagesStatus(FermatMessagesStatus.SENT);
            outgoingMessageDao.update(message);

            /*
             * Put the message on a event and fire new event
             */
            FermatEvent fermatEvent =
                eventManager.getNewEvent(
                    P2pEventType.NEW_NETWORK_SERVICE_MESSAGE_SENT_NOTIFICATION);
            fermatEvent.setSource(AssetIssuerActorNetworkServicePluginRoot.EVENT_SOURCE);
            ((NewNetworkServiceMessageSentNotificationEvent) fermatEvent).setData(message);
            eventManager.raiseEvent(fermatEvent);
          }
        }

      } catch (CantUpdateRecordDataBaseException e) {
        errorManager.reportUnexpectedPluginException(
            Plugins.BITDUBAI_DAP_ASSET_ISSUER_ACTOR_NETWORK_SERVICE,
            UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
            new Exception("Can not process messages to send. Error reason: " + e.getMessage()));
      } catch (CantReadRecordDataBaseException e) {
        errorManager.reportUnexpectedPluginException(
            Plugins.BITDUBAI_DAP_ASSET_ISSUER_ACTOR_NETWORK_SERVICE,
            UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
            new Exception("Can not process messages to send. Error reason: " + e.getMessage()));
      }

      // Sleep for a time
      toSend.sleep(CommunicationNetworkServiceRemoteAgent.SLEEP_TIME);

    } catch (InterruptedException e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.BITDUBAI_DAP_ASSET_ISSUER_ACTOR_NETWORK_SERVICE,
          UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
          new Exception("Can not sleep"));
    }
  }
 private void raiseEvent(EventType eventType) {
   FermatEvent eventToRaise = eventManager.getNewEvent(eventType);
   eventToRaise.setSource(this.eventSource);
   eventManager.raiseEvent(eventToRaise);
 }
 private void removeRegisteredListeners() {
   for (FermatEventListener fermatEventListener : listenersAdded) {
     eventManager.removeListener(fermatEventListener);
   }
   listenersAdded.clear();
 }
  private void initializeListener() {

    /*
     * Listen and handle Complete Component Registration Notification Event
     */
    FermatEventListener fermatEventListener =
        eventManager.getNewListener(P2pEventType.COMPLETE_COMPONENT_REGISTRATION_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new CompleteComponentRegistrationNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * Listen and handle Complete Request List Component Registered Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(
            P2pEventType.COMPLETE_REQUEST_LIST_COMPONENT_REGISTERED_NOTIFICATION);
    //        fermatEventListener.setEventHandler(new
    // CompleteRequestListComponentRegisteredNotificationEventHandler(this));
    //        eventManager.addListener(fermatEventListener);
    //        listenersAdded.add(fermatEventListener);

    /*
     * Listen and handle Complete Request List Component Registered Notification Event
     */
    fermatEventListener =
        eventManager.getNewListener(
            P2pEventType.COMPLETE_COMPONENT_CONNECTION_REQUEST_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new CompleteComponentConnectionRequestNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /** failure connection */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.FAILURE_COMPONENT_CONNECTION_REQUEST_NOTIFICATION);
    fermatEventListener.setEventHandler(
        new FailureComponentConnectionRequestNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /** close connection */
    fermatEventListener = eventManager.getNewListener(P2pEventType.CLIENT_CONNECTION_CLOSE);
    fermatEventListener.setEventHandler(new ClientConnectionCloseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * Listen and handle VPN Connection Close Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.VPN_CONNECTION_CLOSE);
    fermatEventListener.setEventHandler(new VPNConnectionCloseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /** new message */
    fermatEventListener =
        eventManager.getNewListener(P2pEventType.NEW_NETWORK_SERVICE_MESSAGE_RECEIVE_NOTIFICATION);
    fermatEventListener.setEventHandler(new NewReceiveMessagesNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * Listen and handle Client Connection Loose Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.CLIENT_CONNECTION_LOOSE);
    fermatEventListener.setEventHandler(new ClientConnectionLooseNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);

    /*
     * Listen and handle Client Connection Success Reconnect Notification Event
     */
    fermatEventListener = eventManager.getNewListener(P2pEventType.CLIENT_SUCCESS_RECONNECT);
    fermatEventListener.setEventHandler(
        new ClientSuccessfullReconnectNotificationEventHandler(this));
    eventManager.addListener(fermatEventListener);
    listenersAdded.add(fermatEventListener);
  }