1 21 22 package org.jacorb.notification.queue; 23 24 import org.jacorb.notification.interfaces.Message; 25 26 30 public class BasicMessageQueueAdapter implements MessageQueueAdapter 31 { 32 private final MessageQueue queue_; 33 34 private static final Message[] EMPTY = new Message[0]; 35 36 39 public BasicMessageQueueAdapter(MessageQueue queue) 40 { 41 super(); 42 43 queue_ = queue; 44 } 45 46 49 public void enqeue(Message message) 50 { 51 queue_.put(message); 53 } 54 55 60 public boolean hasPendingMessages() 61 { 62 return !queue_.isEmpty(); 63 } 64 65 70 public int getPendingMessagesCount() 71 { 72 return queue_.getSize(); 73 } 74 75 80 public Message getMessageBlocking() throws InterruptedException 81 { 82 return queue_.getMessage(true); 83 } 84 85 90 public Message getMessageNoBlock() throws InterruptedException 91 { 92 return queue_.getMessage(false); 93 } 94 95 100 public Message[] getAllMessages() throws InterruptedException 101 { 102 return queue_.getAllMessages(false); 103 } 104 105 110 public Message[] getUpToMessages(int max) throws InterruptedException 111 { 112 return queue_.getMessages(max, false); 113 } 114 115 120 public Message[] getAtLeastMessages(int min) throws InterruptedException 121 { 122 if (queue_.getSize() >= min) 123 { 124 return queue_.getAllMessages(true); 125 } 126 127 return EMPTY; 128 } 129 130 public void clear() 131 { 132 try 133 { 134 Message[] allMessages = queue_.getAllMessages(false); 135 136 for (int i = 0; i < allMessages.length; i++) 137 { 138 Message message = allMessages[i]; 139 message.dispose(); 140 } 141 } catch (InterruptedException e) 142 { 143 } 145 } 146 147 public String toString() 148 { 149 return queue_.toString(); 150 } 151 } | Popular Tags |