Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. ### METHOD(S)
  2.  
  3. To `Signal a message` you can use the following method(s) in the Java V4 SDK:
  4.  
  5. ```java
  6. this.pubnub.signal().message(Object).channel(String);
  7. ```
  8.  
  9. | Parameter | Type | Required | Description |
  10. | --------- | ---------- | -------- | ----------- |
  11. | `message` | `Object` | Yes | The payload which will be serialized and sent. |
  12. | `channel` | `String` | Yes | The channel which the signal will be sent to. |
  13. | `sync` | `PNPublishResult` | No | Executes the call. Blocks the thread, exception is thrown if something goes wrong. |
  14. | `async` | `PNCallback<PNPublishResult>` | No | Executes the call asynchronously. |
  15.  
  16. ### BASIC USAGE
  17.  
  18. #### SIGNAL A MESSAGE TO A CHANNEL:
  19.  
  20. ```java
  21. pubnub.signal()
  22. .message("Hello everyone!")
  23. .channel("bar")
  24. .async(new PNCallback<PNPublishResult>() {
  25. @Override
  26. public void onResponse(PNPublishResult pnPublishResult, PNStatus pnStatus) {
  27. if (pnStatus.isError()) {
  28. Long timetoken = pnPublishResult.getTimetoken(); // signal message timetoken
  29. } else {
  30. pnStatus.getErrorData().getThrowable().printStackTrace();
  31. }
  32. }
  33. });
  34. ```
  35.  
  36. ### RESPONSE
  37.  
  38. The `signal()` operation returns a `PNPublishResult` object which contains the following operations:
  39.  
  40. | Method | Type | Description |
  41. | ---------------- | ---------- | ------------ |
  42. | `getTimetoken()` | Long | Returns a long representation of the time token when the signal was published.|
  43.  
  44. ### LISTENER
  45.  
  46. Signals arrive at the `signal()` method inside the PubNub's `SubscribeCallback` listener.
  47.  
  48. ```java
  49. pubnub.addListener(new SubscribeCallback() {
  50.  
  51. // other callbacks omitted
  52.  
  53. @Override
  54. public void signal(PubNub pubnub, PNSignalResult pnSignalResult) {
  55. System.out.println("Signal publisher: " + signal.getPublisher());
  56. System.out.println("Signal payload: " + signal.getMessage());
  57. System.out.println("Signal subscription: " + signal.getSubscription());
  58. System.out.println("Signal channel: " + signal.getChannel());
  59. System.out.println("Signal timetoken: " + signal.getTimetoken());
  60. }
  61. });
  62. ```
  63.  
  64. ## SUBSCRIBE RETURNS
  65. The `subscribe()` operation returns a `PNSignalResult` for signals which contains the following operations:
  66.  
  67. | Method | Type | Description |
  68. | ------------------- | ----------------- | ----------------- |
  69. | `getMessage()` | `JsonElement` | The signal sent on the channel. |
  70. | `getSubscription()` | `String` | The channel group or wildcard subscription match (if exists). |
  71. | `getChannel()` | `String` | The channel for which the signal belongs. |
  72. | `getTimetoken()` | `Long` | Timetoken for the signal. |
  73. | `getUserMetadata()` | `Object` | User metadata. |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement