/** Destroys destination - should be executed when the app is uninstalled */ public void destroyReceiver(final String uriStr) { try { final Destination dest = DestinationFactory.getReceiverDestination(URI.create(uriStr)); if (dest != null) { dest.destroy(); } } catch (final Exception e) { alertDialog(e.toString()); } }
/** * Creates non-blocking receiver destination (IPC) for the URI and registers a listener. * * @param uriStr * @param autoStartEnabled Auto-start application on incoming messages */ public void startNonBlockingReceiverIPC(final String uriStr, final boolean autoStartEnabled) { NonBlockingReceiverDestination nonBlockRecvDest = null; try { nonBlockRecvDest = (NonBlockingReceiverDestination) DestinationFactory.getReceiverDestination(URI.create(uriStr)); if (nonBlockRecvDest == null) // Not registered yet { final SimpleListener responseListener = new SimpleListener("NonBlockingReceiverIPC"); // Prepare the inbound destination for incoming // messages (Inter Process Communication). final InboundDestinationConfiguration config = InboundDestinationConfigurationFactory.createIPCConfiguration( autoStartEnabled, true, false); nonBlockRecvDest = DestinationFactory.createNonBlockingReceiverDestination( config, URI.create(uriStr), null, responseListener); } } catch (final Exception e) { alertDialog(e.toString()); } }
/** * Creates receiver destination (BES) for the URI and registers a listener * * @param uriStr URI of the receiver destination * @param autoStartEnabled Auto start application on incoming messages */ public void startNonBlockingReceiverBES(final String uriStr, final boolean autoStartEnabled) { NonBlockingReceiverDestination nonBlockRecvDest = null; try { nonBlockRecvDest = (NonBlockingReceiverDestination) DestinationFactory.getReceiverDestination(URI.create(uriStr)); if (nonBlockRecvDest == null) // Not registered yet { final MessageListener responseListener = new DestinationListener("NonBlockingReceiverBES", true); // Prepare the in-bound destination for incoming messages // (BES/http) final InboundDestinationConfiguration config = InboundDestinationConfigurationFactory.createBESConfiguration( autoStartEnabled, true, false); nonBlockRecvDest = DestinationFactory.createNonBlockingReceiverDestination( config, URI.create(uriStr), responseListener); } } catch (final Exception e) { alertDialog(e.toString()); } }
/** @see Thread#run() */ public void run() { BlockingReceiverDestination blockRecvDest = null; try { blockRecvDest = (BlockingReceiverDestination) DestinationFactory.getReceiverDestination(URI.create(_uriStr)); if (blockRecvDest == null) // Not registered yet { InboundDestinationConfiguration config; // Prepare the inbound destination for incoming messages if (_configType == InboundDestinationConfiguration.CONFIG_TYPE_BES) { config = InboundDestinationConfigurationFactory.createBESConfiguration( _autoStartEnabled, true, false); } else if (_configType == InboundDestinationConfiguration.CONFIG_TYPE_IPC) { config = InboundDestinationConfigurationFactory.createIPCConfiguration( _autoStartEnabled, true, false); } else { throw new IllegalArgumentException( "Invalid InboundDestinationConfiguration type! Implemented support of IPC and BES only."); } blockRecvDest = DestinationFactory.createBlockingReceiverDestination(config, URI.create(_uriStr)); } String alertString = ""; _response = blockRecvDest.receive(_timeout * 1000); if (_response != null) { alertString = "RECEIVED[id: " + _response.getMessageId() + "]:"; final String stringPayload = ((ByteMessage) _response).getStringPayload(); if (stringPayload != null) { alertString += "\n" + stringPayload; } } else { // No response received alertString = "No message has been received during timeout of " + _timeout + " sec."; } alertDialog(alertString); } catch (final Exception e) { alertDialog(e.toString()); } }