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);
  }
 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);
  }
  /**
   * 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"));
    }
  }
Ejemplo n.º 8
0
 private void raiseEvent(EventType eventType) {
   FermatEvent eventToRaise = eventManager.getNewEvent(eventType);
   eventToRaise.setSource(this.eventSource);
   eventManager.raiseEvent(eventToRaise);
 }