/** (non-javadoc) */ public void sendMessage( final String senderIdentityPublicKey, final String pk, final String messageContent) { try { FermatMessage fermatMessage = FermatMessageCommunicationFactory.constructFermatMessage( senderIdentityPublicKey, // Sender NetworkService pk, // Receiver messageContent, // Message Content FermatMessageContentType.TEXT); // Type /* * Configure the correct status */ ((FermatMessageCommunication) fermatMessage) .setFermatMessagesStatus(FermatMessagesStatus.PENDING_TO_SEND); /* * Save to the data base table */ outgoingMessageDao.create(fermatMessage); } catch (Exception e) { e.printStackTrace(); errorManager.reportUnexpectedPluginException( Plugins.BITDUBAI_DAP_ASSET_TRANSMISSION_NETWORK_SERVICE, UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN, new Exception("Can not send message. Error reason: " + e.getMessage())); } }
/** Method tha send a new Message */ public void sendNewMessage( PlatformComponentProfile sender, PlatformComponentProfile destination, String messageContent) throws CantSendMessageException { try { /* * ask for a previous connection */ CommunicationNetworkServiceLocal communicationNetworkServiceLocal = communicationNetworkServiceConnectionManager.getNetworkServiceLocalInstance( destination.getIdentityPublicKey()); if (communicationNetworkServiceLocal != null) { System.out.println( "*** 12345 case 7:send msg in NS P2P layer active connection" + new Timestamp(System.currentTimeMillis())); // Send the message communicationNetworkServiceLocal.sendMessage( sender.getIdentityPublicKey(), sender.getPlatformComponentType(), sender.getNetworkServiceType(), messageContent); } else { System.out.println( "*** 12345 case 6:send msg in NS P2P layer not active connection" + new Timestamp(System.currentTimeMillis())); /* * Created the message */ FermatMessage fermatMessage = FermatMessageCommunicationFactory.constructFermatMessage( sender.getIdentityPublicKey(), // Sender sender.getPlatformComponentType(), // Sender Type sender.getNetworkServiceType(), // Sender NS Type destination.getIdentityPublicKey(), // Receiver destination.getPlatformComponentType(), // Receiver Type destination.getNetworkServiceType(), // Receiver NS Type messageContent, // Message Content FermatMessageContentType.TEXT // Type ); /* * Configure the correct status */ ((FermatMessageCommunication) fermatMessage) .setFermatMessagesStatus(FermatMessagesStatus.PENDING_TO_SEND); /* * Save to the data base table */ communicationNetworkServiceConnectionManager.getOutgoingMessageDao().create(fermatMessage); /* * Ask the client to connect */ communicationNetworkServiceConnectionManager.connectTo( sender, getNetworkServiceProfile(), destination); } } catch (Exception e) { System.out.println("Error sending message: " + e.getMessage()); throw new CantSendMessageException(CantSendMessageException.DEFAULT_MESSAGE, e); } }