1 24 25 package org.objectweb.dream.queue; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.InterruptedPullException; 31 import org.objectweb.dream.Pull; 32 import org.objectweb.dream.PullException; 33 import org.objectweb.dream.message.Message; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.IllegalBindingException; 36 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 37 38 52 public abstract class AbstractPullOutgoingHandlerImpl extends AbstractComponent 53 implements 54 Pull, 55 PullQueueAttributeController 56 { 57 58 protected boolean blockingPull = true; 59 60 protected Buffer bufferItf; 62 protected BufferRemoveFirstLast bufferRemoveFirstLastItf; 63 64 68 71 public synchronized Message pull(Map context) throws PullException 72 { 73 if (!hasAvailableMessage() && !blockingPull) 74 { 75 return null; 76 } 77 try 78 { 79 return doPull(); 80 } 81 catch (InterruptedException e) 82 { 83 throw new InterruptedPullException( 84 "Interrupted while waiting for an available message", e); 85 } 86 } 87 88 92 97 protected abstract boolean hasAvailableMessage(); 98 99 108 protected abstract Message doPull() throws InterruptedException ; 109 110 114 117 public synchronized void setBlockingPull(boolean blockingPull) 118 { 119 this.blockingPull = blockingPull; 120 } 121 122 125 public boolean getBlockingPull() 126 { 127 return blockingPull; 128 } 129 130 134 138 public synchronized void bindFc(String clientItfName, Object serverItf) 139 throws NoSuchInterfaceException, IllegalBindingException, 140 IllegalLifeCycleException 141 { 142 super.bindFc(clientItfName, serverItf); 143 if (clientItfName.equals(Buffer.ITF_NAME)) 144 { 145 bufferItf = (Buffer) serverItf; 146 } 147 else if (clientItfName.equals(BufferRemoveFirstLast.ITF_NAME)) 148 { 149 bufferRemoveFirstLastItf = (BufferRemoveFirstLast) serverItf; 150 } 151 } 152 153 156 public String [] listFc() 157 { 158 return new String []{Buffer.ITF_NAME, BufferRemoveFirstLast.ITF_NAME}; 159 } 160 161 } | Popular Tags |