View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.protocol;
17  
18  import org.fourthline.cling.model.message.StreamRequestMessage;
19  import org.fourthline.cling.model.message.StreamResponseMessage;
20  import org.fourthline.cling.UpnpService;
21  import org.fourthline.cling.transport.RouterException;
22  
23  /**
24   * Supertype for all synchronously executing protocols, sending UPnP messages.
25   * <p>
26   * After instantiation by the {@link ProtocolFactory}, this protocol <code>run()</code>s and
27   * calls its {@link #executeSync()} method.
28   * </p>
29   *
30   * @param <IN> The type of request UPnP message send by this protocol.
31   * @param <OUT> The type of response UPnP message expected by this protocol.
32   *
33   * @author Christian Bauer
34   */
35  public abstract class SendingSync<IN extends StreamRequestMessage, OUT extends StreamResponseMessage> extends SendingAsync {
36  
37      final private IN inputMessage;
38      protected OUT outputMessage;
39  
40      protected SendingSync(UpnpService upnpService, IN inputMessage) {
41          super(upnpService);
42          this.inputMessage = inputMessage;
43      }
44  
45      public IN getInputMessage() {
46          return inputMessage;
47      }
48  
49      public OUT getOutputMessage() {
50          return outputMessage;
51      }
52  
53      final protected void execute() throws RouterException {
54          outputMessage = executeSync();
55      }
56  
57      protected abstract OUT executeSync() throws RouterException;
58  
59      @Override
60      public String toString() {
61          return "(" + getClass().getSimpleName() + ")";
62      }
63  
64  }