@Override @SuppressWarnings("unchecked") public void start() { if (started.compareAndSet(false, true)) { if (parent != null) { parent.addChild(this); if (getLimit() > parent.getLimit()) { LOG.info("Usage({}) limit={} should be smaller than its parent limit={}", new Object[] { getName(), getLimit(), parent.getLimit() }); } } for (T t : children) { t.start(); } } }
if (!parent.waitForSpace(timeout, highWaterMark)) { return false; percentUsage = caclPercentUsage(); if (percentUsage >= highWaterMark) { long deadline = timeout > 0 ? System.currentTimeMillis() + timeout : Long.MAX_VALUE; long timeleft = deadline; while (timeleft > 0) { percentUsage = caclPercentUsage(); if (percentUsage >= highWaterMark) { waitForSpaceCondition.await(pollingTime, TimeUnit.MILLISECONDS);
protected void setPercentUsage(int value) { usageLock.writeLock().lock(); try { int oldValue = percentUsage; percentUsage = value; if (oldValue != value) { fireEvent(oldValue, value); } } finally { usageLock.writeLock().unlock(); } }
@Override public String toString() { return "Usage(" + getName() + ") percentUsage=" + percentUsage + "%, usage=" + retrieveUsage() + ", limit=" + limiter.getLimit() + ", percentUsageMinDelta=" + percentUsageMinDelta + "%" + (parent != null ? ";Parent:" + parent.toString() : ""); }
public boolean isFull(int highWaterMark) { if (parent != null && parent.isFull(highWaterMark)) { return true; } usageLock.writeLock().lock(); try { percentUsage = caclPercentUsage(); return percentUsage >= highWaterMark; } finally { usageLock.writeLock().unlock(); } }
protected void onLimitChange() { // We may need to calculate the limit if (usagePortion > 0 && parent != null) { usageLock.writeLock().lock(); try { this.limiter.setLimit((long) (parent.getLimit() * (double) usagePortion)); } finally { usageLock.writeLock().unlock(); } } // Reset the percent currently being used. usageLock.writeLock().lock(); try { setPercentUsage(caclPercentUsage()); } finally { usageLock.writeLock().unlock(); } // Let the children know that the limit has changed. They may need to // set their limits based on ours. for (T child : children) { child.onLimitChange(); } }
private void fireEvent(final int oldPercentUsage, final int newPercentUsage) { if (debug) { LOG.debug(getName() + ": usage change from: " + oldPercentUsage + "% of available memory, to: " + newPercentUsage + "% of available memory"); if (!callbacks.isEmpty()) { for (Runnable callback : callbacks) { getExecutor().execute(callback); getExecutor().execute(listenerNotifier); } else { LOG.warn("Not notifying memory usage change to listeners on shutdown");
/** * @throws InterruptedException */ public void waitForSpace() throws InterruptedException { waitForSpace(0); }
/** * Sets the minimum number of percentage points the usage has to change before a UsageListener event is fired by the * manager. * * @param percentUsageMinDelta * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryPropertyEditor" */ public void setPercentUsageMinDelta(int percentUsageMinDelta) { if (percentUsageMinDelta < 1) { throw new IllegalArgumentException("percentUsageMinDelta must be greater than 0"); } usageLock.writeLock().lock(); try { this.percentUsageMinDelta = percentUsageMinDelta; setPercentUsage(caclPercentUsage()); } finally { usageLock.writeLock().unlock(); } }
@Override public void isFull(ConnectionContext context, Destination destination, Usage<?> usage) { super.isFull(context, destination, usage); if (AdvisorySupport.isAdvisoryTopic(destination.getActiveMQDestination()) == false) { try { ActiveMQTopic topic = AdvisorySupport.getFullAdvisoryTopic(destination.getActiveMQDestination()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_USAGE_NAME, usage.getName()); advisoryMessage.setLongProperty(AdvisorySupport.MSG_PROPERTY_USAGE_COUNT, usage.getUsage()); fireAdvisory(context, topic, null, null, advisoryMessage); } catch (Exception e) { handleFireFailure("is full", e); } } }
public void onUsageChanged(Usage usage, int oldPercentUsage, int newPercentUsage) { // Do we need to start evicting cache entries? Usage > than the // high mark if (oldPercentUsage < newPercentUsage && usage.getPercentUsage() >= usageHighMark) { try { evictionTask.wakeup(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
@Override public String toString() { return "Usage(" + getName() + ") percentUsage=" + percentUsage + "%, usage=" + retrieveUsage() + " limit=" + limiter.getLimit() + " percentUsageMinDelta=" + percentUsageMinDelta + "%"; }
public Usage(T parent, String name, float portion) { this.parent = parent; this.usagePortion = portion; if (parent != null) { this.limiter.setLimit((long) (parent.getLimit() * (double)portion)); name = parent.name + ":" + name; } this.name = name; }
public boolean isFull() { return isFull(100); }
if (parent.notifyCallbackWhenNotFull(r)) { return true;
@Override public void isFull(ConnectionContext context, Destination destination, Usage usage) { super.isFull(context, destination, usage); if (AdvisorySupport.isAdvisoryTopic(destination.getActiveMQDestination()) == false) { try { ActiveMQTopic topic = AdvisorySupport.getFullAdvisoryTopic(destination.getActiveMQDestination()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_USAGE_NAME, usage.getName()); fireAdvisory(context, topic, null, null, advisoryMessage); } catch (Exception e) { handleFireFailure("is full", e); } } }
protected void onLimitChange() { // We may need to calculate the limit if (usagePortion > 0 && parent != null) { synchronized (usageMutex) { this.limiter.setLimit((long)(parent.getLimit() * usagePortion)); } } // Reset the percent currently being used. int percentUsage; synchronized (usageMutex) { percentUsage = caclPercentUsage(); } setPercentUsage(percentUsage); // Let the children know that the limit has changed. They may need to // set // their limits based on ours. for (T child : children) { child.onLimitChange(); } }
@Override public String toString() { return "Usage(" + getName() + ") percentUsage=" + percentUsage + "%, usage=" + retrieveUsage() + ", limit=" + limiter.getLimit() + ", percentUsageMinDelta=" + percentUsageMinDelta + "%" + (parent != null ? ";Parent:" + parent.toString() : ""); }
private void fireEvent(final int oldPercentUsage, final int newPercentUsage) { if (debug) { LOG.debug(getName() + ": usage change from: " + oldPercentUsage + "% of available memory, to: " + newPercentUsage + "% of available memory"); if (!callbacks.isEmpty()) { for (Runnable callback : callbacks) { getExecutor().execute(callback); getExecutor().execute(listenerNotifier); } else { LOG.warn("Not notifying memory usage change to listeners on shutdown");