1 64 package com.jcorporate.expresso.kernel; 65 66 import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock; 67 import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock; 68 import org.apache.log4j.Logger; 69 70 79 abstract public class ContainerComponentBase extends ComponentBase implements Containable { 80 81 84 private ReadWriteLock containerLock = new WriterPreferenceReadWriteLock(); 85 86 87 90 private static Logger log = Logger.getLogger(ContainerComponentBase.class); 91 92 95 private ComponentContainer implementation; 96 97 100 public ContainerComponentBase() { 101 super(); 102 } 103 104 105 112 public synchronized void setContainerImplementation(ComponentContainer newContainer) { 113 try { 114 containerLock.writeLock().acquire(); 115 } catch (InterruptedException ex) { 116 log.error("Interrupted while waiting for write lock. Aborting method", ex); 117 } 118 implementation = newContainer; 119 120 containerLock.writeLock().release(); 121 } 122 123 124 129 public synchronized ComponentContainer getContainerImplementation() { 130 try { 131 containerLock.readLock().acquire(); 132 } catch (InterruptedException ex) { 133 log.error("Interrupted while waiting for read lock. Aborting method", ex); 134 } 135 136 try { 137 return implementation; 138 } finally { 139 containerLock.readLock().release(); 140 } 141 } 142 143 158 public synchronized ExpressoComponent locateComponent(String componentName) { 159 try { 160 containerLock.readLock().acquire(); 161 } catch (InterruptedException ex) { 162 log.error("Interrupted while waiting for read lock. Aborting method", ex); 163 } 164 165 try { 166 return implementation.locateComponent(componentName); 167 } finally { 168 containerLock.readLock().release(); 169 } 170 } 171 } | Popular Tags |