Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Client.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_web;
  23. import com.dmdirc.addons.ui_web.uicomponents.WebWindow;
  24. import com.dmdirc.ui.interfaces.Window;
  25. import java.util.LinkedList;
  26. import java.util.List;
  27. import org.mortbay.util.ajax.Continuation;
  28. /**
  29. *
  30. * @author chris
  31. */
  32. public class Client {
  33. private long lastSeenTime = System.currentTimeMillis();
  34. private Continuation continuation;
  35. private final String ip;
  36. private final List<Event> events = new LinkedList<Event>();
  37. public Client(final WebInterfaceUI controller, final String ip) {
  38. events.add(new Event("statusbar",
  39. "Welcome to the DMDirc web interface"));
  40. this.ip = ip;
  41. final List<Window> added = new LinkedList<Window>();
  42. final List<Window> queued = new LinkedList<Window>(
  43. WebWindow.getWindows());
  44. while (!queued.isEmpty()) {
  45. final Window window = queued.remove(0);
  46. final Window parent = controller.getWindowManager()
  47. .getWindow(window.getContainer().getParent());
  48. if (parent == null) {
  49. events.add(new Event("newwindow", window));
  50. added.add(window);
  51. } else if (added.contains(parent)) {
  52. events.add(new Event("newchildwindow", new Object[]{parent, window}));
  53. added.add(window);
  54. } else {
  55. queued.add(window);
  56. }
  57. }
  58. }
  59. public String getIp() {
  60. return ip;
  61. }
  62. public long getTime() {
  63. return System.currentTimeMillis() - lastSeenTime;
  64. }
  65. public Object getMutex() {
  66. return events;
  67. }
  68. public void setContinuation(final Continuation continuation) {
  69. this.continuation = continuation;
  70. }
  71. public void touch() {
  72. lastSeenTime = System.currentTimeMillis();
  73. }
  74. public void addEvent(final Event event) {
  75. synchronized (events) {
  76. events.add(event);
  77. if (continuation != null) {
  78. continuation.resume();
  79. }
  80. }
  81. }
  82. public List<Event> retrieveEvents() {
  83. synchronized (events) {
  84. final List<Event> res = new LinkedList<Event>(events);
  85. events.clear();
  86. return res;
  87. }
  88. }
  89. public int getEventCount() {
  90. return events.size();
  91. }
  92. }