1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.protocol;
17
18 import org.fourthline.cling.UpnpService;
19 import org.fourthline.cling.transport.RouterException;
20 import org.seamless.util.Exceptions;
21
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public abstract class SendingAsync implements Runnable {
39
40 final private static Logger log = Logger.getLogger(UpnpService.class.getName());
41
42 private final UpnpService upnpService;
43
44 protected SendingAsync(UpnpService upnpService) {
45 this.upnpService = upnpService;
46 }
47
48 public UpnpService getUpnpService() {
49 return upnpService;
50 }
51
52 public void run() {
53 try {
54 execute();
55 } catch (Exception ex) {
56 Throwable cause = Exceptions.unwrap(ex);
57 if (cause instanceof InterruptedException) {
58 log.log(Level.INFO, "Interrupted protocol '" + getClass().getSimpleName() + "': " + ex, cause);
59 } else {
60 throw new RuntimeException(
61 "Fatal error while executing protocol '" + getClass().getSimpleName() + "': " + ex, ex
62 );
63 }
64 }
65 }
66
67 protected abstract void execute() throws RouterException;
68
69 @Override
70 public String toString() {
71 return "(" + getClass().getSimpleName() + ")";
72 }
73
74 }