Protocol.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package de.tudarmstadt.informatik.hostage.protocol;
  2. import java.util.List;
  3. /**
  4. * Interface for protocols that are used by hostage
  5. * @param <T> Denotes if the protocol is using Strings or ByteArrays
  6. */
  7. public interface Protocol<T> {
  8. /**
  9. * Represents who starts the communication once the connection is established
  10. */
  11. public static enum TALK_FIRST {
  12. SERVER, CLIENT
  13. };
  14. /**
  15. * Returns the port on which the protocol is running
  16. * @return the port used by the protocol (range: 0-65535)
  17. */
  18. int getPort();
  19. /**
  20. * Returns who starts the communication (server or client)
  21. * @return TALK_FIRST.server if the server starts or TALK_FIRST.client if the client starts
  22. */
  23. TALK_FIRST whoTalksFirst();
  24. /**
  25. * Determines the next message that is sent by the server
  26. * @param message last message that was sent by the client
  27. * @return next message that will be sent
  28. */
  29. List<T> processMessage(T message);
  30. /**
  31. * Returns whether the communication is ended and the connection should be closed or not
  32. * @return true if the connection should be closed, else false
  33. */
  34. boolean isClosed();
  35. /**
  36. * Returns if the protocol uses SSL/TLS connection or not
  37. * @return true if SSL/TLS is used, else false
  38. */
  39. boolean isSecure();
  40. /**
  41. * Returns what type the protocol is using, Strings or ByteArrays
  42. * @return the class that the protocol is using
  43. */
  44. Class<T> getType();
  45. /**
  46. * Returns the name of the protocol
  47. * @return name of the protocol
  48. */
  49. @Override
  50. String toString();
  51. }