| 1 | package be.nikiroo.utils.serial.server; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.Socket; |
| 5 | |
| 6 | import be.nikiroo.utils.Version; |
| 7 | |
| 8 | /** |
| 9 | * Class used for the server basic handling. |
| 10 | * <p> |
| 11 | * It represents a single action: a server is expected to execute one action for |
| 12 | * each client action. |
| 13 | * |
| 14 | * @author niki |
| 15 | */ |
| 16 | public class ConnectActionServerObject extends ConnectActionServer { |
| 17 | /** |
| 18 | * Create a new {@link ConnectActionServerObject} with the current |
| 19 | * application version (see {@link Version#getCurrentVersion()}) as the |
| 20 | * server version. |
| 21 | * |
| 22 | * @param s |
| 23 | * the socket to bind to |
| 24 | */ |
| 25 | public ConnectActionServerObject(Socket s) { |
| 26 | super(s); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Create a new {@link ConnectActionServerObject}. |
| 31 | * |
| 32 | * @param s |
| 33 | * the socket to bind to |
| 34 | * @param version |
| 35 | * the server version |
| 36 | */ |
| 37 | public ConnectActionServerObject(Socket s, Version version) { |
| 38 | super(s, version); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Serialise and send the given object to the client. |
| 43 | * |
| 44 | * @param data |
| 45 | * the data to send |
| 46 | * |
| 47 | * @throws IOException |
| 48 | * in case of I/O error |
| 49 | * @throws NoSuchFieldException |
| 50 | * if the serialised data contains information about a field |
| 51 | * which does actually not exist in the class we know of |
| 52 | * @throws NoSuchMethodException |
| 53 | * if a class described in the serialised data cannot be created |
| 54 | * because it is not compatible with this code |
| 55 | * @throws ClassNotFoundException |
| 56 | * if a class described in the serialised data cannot be found |
| 57 | */ |
| 58 | public void send(Object data) throws IOException, NoSuchFieldException, |
| 59 | NoSuchMethodException, ClassNotFoundException { |
| 60 | action.sendObject(data); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * (Flush the data to the client if needed and) retrieve its answer. |
| 65 | * |
| 66 | * @return the deserialised answer (which can actually be NULL) |
| 67 | * |
| 68 | * @throws IOException |
| 69 | * in case of I/O error |
| 70 | * @throws NoSuchFieldException |
| 71 | * if the serialised data contains information about a field |
| 72 | * which does actually not exist in the class we know of |
| 73 | * @throws NoSuchMethodException |
| 74 | * if a class described in the serialised data cannot be created |
| 75 | * because it is not compatible with this code |
| 76 | * @throws ClassNotFoundException |
| 77 | * if a class described in the serialised data cannot be found |
| 78 | * @throws java.lang.NullPointerException |
| 79 | * if the counter part has no data to send |
| 80 | */ |
| 81 | public Object rec() throws NoSuchFieldException, NoSuchMethodException, |
| 82 | ClassNotFoundException, IOException, java.lang.NullPointerException { |
| 83 | return action.recObject(); |
| 84 | } |
| 85 | } |