/** * Never call this method without having successfully called * {@link #pop(long, java.util.concurrent.TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @return false if the pool max size was exceeded */ public boolean push(T obj) { return push(obj, 0); }
/** * Never call this method without having successfully called * {@link #pop(long, TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @return false if the pool max size was exceeded */ public boolean push(final T obj) { return push(obj, 0); }
/** * Never call this method without having successfully called * {@link #pop(long, TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @return false if the pool max size was exceeded */ public boolean push(final T obj) { return push(obj, 0); }
public boolean push(Entry<T> entry) { return push(entry, false); }
public boolean push(final Entry entry) { return push(entry, false); }
public boolean push(final Entry entry) { return push(entry, false); }
/** * Attempt to aquire a permit to add the object to the pool. * * @param obj object to add to the pool * @param offset creation time offset, used for maxAge * @return true of the item as added */ public boolean add(T obj, long offset) { try { if (available.tryAcquire(100, MILLISECONDS)) { try { if (push(obj, offset)) return true; available.release(); } catch (RuntimeException e) { available.release(); throw e; } } return false; } catch (InterruptedException e) { Thread.interrupted(); e.printStackTrace(); } return false; }
/** * Attempt to aquire a permit to add the object to the pool. * * @param obj object to add to the pool * @param offset creation time offset, used for maxAge * @return true of the item as added */ public boolean add(final T obj, final long offset) { try { if (available.tryAcquire(100, MILLISECONDS)) { try { if (push(obj, offset)) { return true; } available.release(); } catch (final RuntimeException e) { available.release(); throw e; } } return false; } catch (final InterruptedException e) { Thread.interrupted(); e.printStackTrace(); } return false; }
/** * Attempt to aquire a permit to add the object to the pool. * * @param obj object to add to the pool * @param offset creation time offset, used for maxAge * @return true of the item as added */ public boolean add(final T obj, final long offset) { try { if (available.tryAcquire(100, MILLISECONDS)) { try { if (push(obj, offset)) { return true; } available.release(); } catch (final RuntimeException e) { available.release(); throw e; } } return false; } catch (final InterruptedException e) { Thread.interrupted(); e.printStackTrace(); } return false; }
/** * This internal method allows us to "swap" the status * of two entries before returning them to the pool. * <p/> * This allows us to elect a replacement in the min pool * without ever loosing loosing pool consistency. * <p/> * Neither argument is allowed to be null. * * @param hard the "min" pool item that will be discarded * @param soft the "min" pool item to replace the discarded instance */ private void discardAndReplace(final Entry hard, final Entry soft) { // The replacement becomes a hard reference -- a "min" pool item soft.hard.set(soft.active()); push(soft); // The discarded item becomes a soft reference hard.hard.set(null); discard(hard); }
/** * This internal method allows us to "swap" the status * of two entries before returning them to the pool. * <p/> * This allows us to elect a replacement in the min pool * without ever loosing loosing pool consistency. * <p/> * Neither argument is allowed to be null. * * @param hard the "min" pool item that will be discarded * @param soft the "min" pool item to replace the discarded instance */ private void discardAndReplace(final Entry hard, final Entry soft) { // The replacement becomes a hard reference -- a "min" pool item soft.hard.set(soft.active()); push(soft); // The discarded item becomes a soft reference hard.hard.set(null); discard(hard); }
/** * This internal method allows us to "swap" the status * of two entries before returning them to the pool. * <p/> * This allows us to elect a replacement in the min pool * without ever loosing loosing pool consistency. * <p/> * Neither argument is allowed to be null. * * @param hard the "min" pool item that will be discarded * @param weak the "min" pool item to replace the discarded instance */ private void discardAndReplace(Entry<T> hard, Entry<T> weak) { // The replacement becomes a hard reference -- a "min" pool item weak.hard.set(weak.get()); push(weak); // The discarded item becomes a weak reference hard.hard.set(null); discard(hard); }
/** * Never call this method without having successfully called * {@link #pop(long, java.util.concurrent.TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @param offset * @return false if the pool max size was exceeded */ private boolean push(T obj, long offset) { if (instances.tryAcquire()){ return push(new Entry<T>(obj, offset, poolVersion.get())); } if (obj != null) new Discard(obj, Event.FULL).run(); return false; }
/** * Never call this method without having successfully called * {@link #pop(long, TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @param offset long * @return false if the pool max size was exceeded */ private boolean push(final T obj, final long offset) { if (instances.tryAcquire()) { return push(new Entry(obj, offset)); } if (obj != null) { new Discard(obj, Event.FULL).run(); } if (available instanceof Overdraft) { available.release(); } return false; }
/** * Never call this method without having successfully called * {@link #pop(long, TimeUnit)} beforehand. * <p/> * Failure to do so will increase the max pool size by one. * * @param obj object to push onto the pool * @param offset long * @return false if the pool max size was exceeded */ private boolean push(final T obj, final long offset) { if (instances.tryAcquire()) { return push(new Entry(obj, offset)); } if (obj != null) { new Discard(obj, Event.FULL).run(); } if (available instanceof Overdraft) { available.release(); } return false; }
/** * All instances are removed from the pool in getInstance(...). They are only * returned by the StatelessContainer via this method under two circumstances. * <p/> * 1. The business method returns normally * 2. The business method throws an application exception * <p/> * Instances are not returned to the pool if the business method threw a system * exception. * * @param callContext ThreadContext * @param bean Object * @throws OpenEJBException */ public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException { if (bean == null) { throw new SystemException("Invalid arguments"); } final Instance instance = Instance.class.cast(bean); final BeanContext beanContext = callContext.getBeanContext(); final Data data = (Data) beanContext.getContainerData(); final Pool<Instance> pool = data.getPool(); if (instance.getPoolEntry() != null) { pool.push(instance.getPoolEntry()); } else { pool.push(instance); } }
/** * All instances are removed from the pool in getInstance(...). They are only * returned by the Container via this method under two circumstances. * <p/> * 1. The business method returns normally * 2. The business method throws an application exception * <p/> * Instances are not returned to the pool if the business method threw a system * exception. * * @param callContext ThreadContext * @param bean Object * @throws OpenEJBException */ public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException { if (bean == null) { throw new SystemException("Invalid arguments"); } final Instance instance = Instance.class.cast(bean); final BeanContext beanContext = callContext.getBeanContext(); final Data data = (Data) beanContext.getContainerData(); final Pool<Instance> pool = data.getPool(); if (instance.getPoolEntry() != null) { pool.push(instance.getPoolEntry()); } else { pool.push(instance); } }
/** * All instances are removed from the pool in getInstance(...). They are only * returned by the StatelessContainer via this method under two circumstances. * * 1. The business method returns normally * 2. The business method throws an application exception * * Instances are not returned to the pool if the business method threw a system * exception. * * @param callContext * @param bean * @throws OpenEJBException */ public void poolInstance(ThreadContext callContext, Object bean) throws OpenEJBException { if (bean == null) throw new SystemException("Invalid arguments"); Instance instance = Instance.class.cast(bean); CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo(); Data data = (Data) deploymentInfo.getContainerData(); Pool<Instance> pool = data.getPool(); if (instance.getPoolEntry() != null){ pool.push(instance.getPoolEntry()); } else { pool.push(instance); } }
/** * All instances are removed from the pool in getInstance(...). They are only * returned by the StatelessContainer via this method under two circumstances. * <p/> * 1. The business method returns normally * 2. The business method throws an application exception * <p/> * Instances are not returned to the pool if the business method threw a system * exception. * * @param callContext ThreadContext * @param bean Object * @throws OpenEJBException */ public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException { if (bean == null) { throw new SystemException("Invalid arguments"); } final Instance instance = Instance.class.cast(bean); final BeanContext beanContext = callContext.getBeanContext(); final Data data = (Data) beanContext.getContainerData(); final Pool<Instance> pool = data.getPool(); if (instance.getPoolEntry() != null) { pool.push(instance.getPoolEntry()); } else { pool.push(instance); } }
pool.push(entry); snooze();