1 24 25 package org.objectweb.dream.cache; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.Pull; 31 import org.objectweb.dream.PullException; 32 import org.objectweb.dream.message.Message; 33 import org.objectweb.dream.message.manager.MessageManager; 34 import org.objectweb.dream.time.GetTimeStamp; 35 import org.objectweb.fractal.api.NoSuchInterfaceException; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 39 47 public class CacheImpl extends AbstractComponent 48 implements 49 Pull, 50 CacheAttributeController 51 { 52 53 54 protected long timeOut = 0; 55 56 57 protected MessageManager messageManagerItf; 58 59 60 protected GetTimeStamp getTimeStamp; 61 62 63 protected Pull inPull; 64 65 66 protected Message cachedMessage; 67 68 69 protected long lastTimeStamp; 70 71 75 78 public Message pull(Map context) throws PullException 79 { 80 long currentTimeStamp = getTimeStamp.getTimeStamp(); 81 if (currentTimeStamp - lastTimeStamp > timeOut) 82 { 83 lastTimeStamp = currentTimeStamp; 84 messageManagerItf.deleteMessage(cachedMessage); 85 cachedMessage = inPull.pull(context); 86 } 87 return messageManagerItf.duplicateMessage(cachedMessage, true); 88 } 89 90 94 97 public void setTimeOut(long timeOut) 98 { 99 this.timeOut = timeOut; 100 } 101 102 105 public long getTimeOut() 106 { 107 return timeOut; 108 } 109 110 114 118 public synchronized void bindFc(String clientItfName, Object serverItf) 119 throws NoSuchInterfaceException, IllegalBindingException, 120 IllegalLifeCycleException 121 { 122 super.bindFc(clientItfName, serverItf); 123 if (clientItfName.equals(Pull.IN_PULL_ITF_NAME)) 124 { 125 inPull = (Pull) serverItf; 126 } 127 else if (clientItfName.equals(GetTimeStamp.ITF_NAME)) 128 { 129 getTimeStamp = (GetTimeStamp) serverItf; 130 } 131 else if (clientItfName.equals(MessageManager.ITF_NAME)) 132 { 133 messageManagerItf = (MessageManager) serverItf; 134 } 135 } 136 137 140 public String [] listFc() 141 { 142 return new String []{Pull.IN_PULL_ITF_NAME, MessageManager.ITF_NAME, 143 GetTimeStamp.ITF_NAME}; 144 } 145 146 } | Popular Tags |