1 24 25 package org.objectweb.dream.queue; 26 27 import org.objectweb.dream.message.Message; 28 import org.objectweb.dream.message.manager.MessageManager; 29 import org.objectweb.fractal.api.NoSuchInterfaceException; 30 import org.objectweb.fractal.api.control.IllegalBindingException; 31 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 32 33 44 public class BufferImpl extends AbstractBufferImpl 45 { 46 47 ListAddFirstLast listAddFirstLastItf; 48 ListRemoveFirstLast listRemoveFirstLastItf; 49 List listItf; 50 51 55 58 protected boolean hasAvailableMessage() 59 { 60 return (availableMessagesIndicator > 0); 61 } 62 63 66 protected boolean canAdd(Message message) 67 { 68 if (maxCapacity > 0 && (maxCapacity - storedMessagesIndicator <= 0)) 69 { 70 return false; 71 } 72 return true; 73 } 74 75 79 82 protected void doAdd(Message message) 83 { 84 listItf.add(message); 85 incrementAvailableMessagesIndicator(1); 86 incrementStoredMessagesIndicator(1); 87 } 88 89 92 protected Message doRemove() 93 { 94 incrementAvailableMessagesIndicator(-1); 95 incrementStoredMessagesIndicator(-1); 96 return (Message) listRemoveFirstLastItf.removeFirst(); 97 } 98 99 102 protected Message doGet() 103 { 104 return (Message) listRemoveFirstLastItf.getFirst(); 105 } 106 107 111 114 protected void doAddFirst(Message message) 115 { 116 listAddFirstLastItf.addFirst(message); 117 incrementAvailableMessagesIndicator(1); 118 incrementStoredMessagesIndicator(1); 119 } 120 121 124 protected void doAddLast(Message message) 125 { 126 listAddFirstLastItf.addLast(message); 127 incrementAvailableMessagesIndicator(1); 128 incrementStoredMessagesIndicator(1); 129 } 130 131 135 138 protected Message doGetFirst() 139 { 140 return (Message) listRemoveFirstLastItf.getFirst(); 141 } 142 143 146 protected Message doGetLast() 147 { 148 return (Message) listRemoveFirstLastItf.getLast(); 149 } 150 151 154 protected Message doRemoveFirst() 155 { 156 incrementAvailableMessagesIndicator(-1); 157 incrementStoredMessagesIndicator(-1); 158 return (Message) listRemoveFirstLastItf.removeFirst(); 159 } 160 161 164 protected Message doRemoveLast() 165 { 166 incrementAvailableMessagesIndicator(-1); 167 incrementStoredMessagesIndicator(-1); 168 return (Message) listRemoveFirstLastItf.removeLast(); 169 } 170 171 175 179 public synchronized void bindFc(String clientItfName, Object serverItf) 180 throws NoSuchInterfaceException, IllegalBindingException, 181 IllegalLifeCycleException 182 { 183 super.bindFc(clientItfName, serverItf); 184 if (clientItfName.equals(List.ITF_NAME)) 185 { 186 listItf = (List) serverItf; 187 } 188 else if (clientItfName.equals(ListAddFirstLast.ITF_NAME)) 189 { 190 listAddFirstLastItf = (ListAddFirstLast) serverItf; 191 } 192 else if (clientItfName.equals(ListRemoveFirstLast.ITF_NAME)) 193 { 194 listRemoveFirstLastItf = (ListRemoveFirstLast) serverItf; 195 } 196 } 197 198 201 public String [] listFc() 202 { 203 return new String []{MessageManager.ITF_NAME, ListAddFirstLast.ITF_NAME, 204 ListRemoveFirstLast.ITF_NAME, List.ITF_NAME}; 205 } 206 207 } | Popular Tags |