1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.protocol.sync;
17
18 import java.util.logging.Logger;
19 import org.fourthline.cling.UpnpService;
20 import org.fourthline.cling.model.gena.LocalGENASubscription;
21 import org.fourthline.cling.model.message.StreamResponseMessage;
22 import org.fourthline.cling.model.message.gena.OutgoingEventRequestMessage;
23 import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
24 import org.fourthline.cling.protocol.SendingSync;
25 import org.fourthline.cling.transport.RouterException;
26
27 import java.net.URL;
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class SendingEvent extends SendingSync<OutgoingEventRequestMessage, StreamResponseMessage> {
42
43 final private static Logger log = Logger.getLogger(SendingEvent.class.getName());
44
45 final protected String subscriptionId;
46 final protected OutgoingEventRequestMessage[] requestMessages;
47 final protected UnsignedIntegerFourBytes currentSequence;
48
49 public SendingEvent(UpnpService upnpService, LocalGENASubscription subscription) {
50 super(upnpService, null);
51
52
53
54 subscriptionId = subscription.getSubscriptionId();
55
56 requestMessages = new OutgoingEventRequestMessage[subscription.getCallbackURLs().size()];
57 int i = 0;
58 for (URL url : subscription.getCallbackURLs()) {
59 requestMessages[i] = new OutgoingEventRequestMessage(subscription, url);
60 getUpnpService().getConfiguration().getGenaEventProcessor().writeBody(requestMessages[i]);
61 i++;
62 }
63
64 currentSequence = subscription.getCurrentSequence();
65
66
67
68 subscription.incrementSequence();
69 }
70
71 protected StreamResponseMessage executeSync() throws RouterException {
72
73 log.fine("Sending event for subscription: " + subscriptionId);
74
75 StreamResponseMessage lastResponse = null;
76
77 for (OutgoingEventRequestMessage requestMessage : requestMessages) {
78
79 if (currentSequence.getValue() == 0) {
80 log.fine("Sending initial event message to callback URL: " + requestMessage.getUri());
81 } else {
82 log.fine("Sending event message '"+currentSequence+"' to callback URL: " + requestMessage.getUri());
83 }
84
85
86
87 lastResponse = getUpnpService().getRouter().send(requestMessage);
88 log.fine("Received event callback response: " + lastResponse);
89
90 }
91
92
93
94 return lastResponse;
95
96 }
97 }