Ejemplo n.º 1
0
  /**
   * Starts the service in the Notification Sender mode
   *
   * @throws NotificationServiceException Is thrown if failed to start the SenderTransport
   */
  public void startSenderTransport() throws NotificationServiceException {

    GenericLogger logger = nativePlatform.getNativeLogger();
    BusAttachment busAttachment = Transport.getInstance().getBusAttachment();

    logger.debug(TAG, "Starting a sender transport");

    // Creating transportChannel objects
    transportSenderChannels =
        new EnumMap<NotificationMessageType, TransportChannelObject>(NotificationMessageType.class);
    try {
      for (NotificationMessageType messageType : NotificationMessageType.values()) {
        transportSenderChannels.put(
            messageType, new TransportChannelObject(messageType, busAttachment, nativePlatform));
      }
    } catch (NotificationServiceException nse) {
      logger.error(TAG, nse.getMessage());
      throw nse;
    }

    // Initialize the NotificationProducer BusObject
    notifProducerBusObj = new NotificationProducerImpl(this, nativePlatform);
    notifProducerBusObj.init();

    // Create session listener to be ready to handle incoming connections
    sessionListener = new SenderSessionListener(nativePlatform);
    sessionListener.init();

    // //Send the Announce signal with all the NotificationService related
    // BusObjectDescription objects
    // if ( aboutObj != null ) {
    // aboutObj.announce();
    // }
  } // startSenderTransport
Ejemplo n.º 2
0
  /**
   * Called when we need to send a signal
   *
   * @param version The version of the message signature
   * @param msgId notification Id the id of the sent signal
   * @param messageType The message type of the sent message
   * @param deviceId Device id
   * @param deviceName Device name
   * @param appId App id
   * @param appName App name
   * @param attributes All the notification metadata
   * @param customAttributes The customAttributes
   * @param text Array of texts to be sent
   * @param ttl Notification message TTL
   * @throws NotificationServiceException
   */
  public void sendNotification(
      int version,
      int msgId,
      NotificationMessageType messageType,
      String deviceId,
      String deviceName,
      byte[] appId,
      String appName,
      Map<Integer, Variant> attributes,
      Map<String, String> customAttributes,
      TransportNotificationText[] text,
      int ttl)
      throws NotificationServiceException {

    GenericLogger logger = nativePlatform.getNativeLogger();

    if (stopSending) {
      logger.debug(TAG, "In stopSending mode NOT sending notification!!!");
      return;
    }

    TransportChannelObject senderChannel = transportSenderChannels.get(messageType);
    if (senderChannel == null) {
      throw new NotificationServiceException(
          "Received an unknown message type: '"
              + messageType
              + "', can't find a transport channel to send the notification");
    }

    // send this notification to the correct object based on messageType
    senderChannel.sendNotification(
        version,
        msgId,
        messageType.getTypeId(),
        deviceId,
        deviceName,
        appId,
        appName,
        attributes,
        customAttributes,
        text,
        ttl);
  } // sendNotification