You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReceiveAdapter.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package chatProg.controller;
  7. import java.util.concurrent.Flow;
  8. import java.util.logging.Logger;
  9. import chatProg.logger.OhmLogger;
  10. import chatProg.model.ChatModel;
  11. import chatProg.view.ChatView;
  12. /**
  13. *
  14. * @author hd, chris
  15. */
  16. public class ReceiveAdapter implements Flow.Subscriber<String>
  17. {
  18. private static Logger lg = OhmLogger.getLogger();
  19. private ChatView view;
  20. private ChatModel model;
  21. private Flow.Subscription subscription;
  22. public ReceiveAdapter(ChatView view, ChatModel model)
  23. {
  24. this.view = view;
  25. this.model = model;
  26. }
  27. public void subscribe()
  28. {
  29. model.addSubscription(this);
  30. }
  31. @Override
  32. public void onSubscribe(Flow.Subscription subscription)
  33. {
  34. this.subscription = subscription;
  35. subscription.request(1);
  36. }
  37. @Override
  38. public void onNext(String item)
  39. {
  40. view.getLblStatusDialog().setText("Nachricht empfangen");
  41. view.getjTextArea().append("Partner: " + item + "\n");
  42. subscription.request(1);
  43. //System.out.println(item);
  44. }
  45. @Override
  46. public void onError(Throwable throwable)
  47. {
  48. }
  49. @Override
  50. public void onComplete()
  51. {
  52. }
  53. }