diff options
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal')
89 files changed, 23 insertions, 9034 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java index 8cb775704a..b72f0448d9 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java @@ -10,15 +10,15 @@ **************************************************************************/ package org.eclipse.net4j.internal.util.bundle; -import org.eclipse.net4j.internal.util.om.log.Logger; import org.eclipse.net4j.internal.util.om.pref.Preferences; -import org.eclipse.net4j.internal.util.om.trace.Tracer; import org.eclipse.net4j.util.ReflectUtil; import org.eclipse.net4j.util.io.IOUtil; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.log.Logger; import org.eclipse.net4j.util.om.log.OMLogger; import org.eclipse.net4j.util.om.trace.OMTracer; +import org.eclipse.net4j.util.om.trace.Tracer; import java.io.File; import java.io.IOException; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java index 172927f6f8..c6a21bc8b7 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractPlatform.java @@ -12,13 +12,13 @@ package org.eclipse.net4j.internal.util.bundle; import org.eclipse.net4j.internal.util.om.LegacyPlatform; import org.eclipse.net4j.internal.util.om.OSGiPlatform; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; import org.eclipse.net4j.util.io.IOUtil; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMPlatform; import org.eclipse.net4j.util.om.log.OMLogHandler; import org.eclipse.net4j.util.om.log.OMLogger; import org.eclipse.net4j.util.om.log.OMLogger.Level; +import org.eclipse.net4j.util.om.trace.ContextTracer; import org.eclipse.net4j.util.om.trace.OMTraceHandler; import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java index 9aa054abcf..ff7c61ce5e 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java @@ -12,15 +12,15 @@ package org.eclipse.net4j.internal.util.bundle; import org.eclipse.net4j.internal.util.container.PluginContainer; import org.eclipse.net4j.internal.util.om.OSGiBundle; -import org.eclipse.net4j.internal.util.om.log.EclipseLoggingBridge; -import org.eclipse.net4j.internal.util.om.log.PrintLogHandler; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler; import org.eclipse.net4j.util.container.IPluginContainer; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.log.EclipseLoggingBridge; import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.log.PrintLogHandler; +import org.eclipse.net4j.util.om.trace.ContextTracer; import org.eclipse.net4j.util.om.trace.OMTracer; +import org.eclipse.net4j.util.om.trace.PrintTraceHandler; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/Cache.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/Cache.java deleted file mode 100644 index 5f8f84a93d..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/Cache.java +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.cache; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.lifecycle.Worker; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.util.cache.ICache; -import org.eclipse.net4j.util.cache.ICacheMonitor; -import org.eclipse.net4j.util.cache.ICacheProbe; - -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; - -/** - * @author Eike Stepper - */ -public abstract class Cache<E> extends Worker implements ICache -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, Cache.class); - - private ICacheMonitor cacheMonitor; - - private ICacheProbe cacheProbe; - - private ReferenceQueue<E> referenceQueue = new ReferenceQueue<E>(); - - public Cache() - { - } - - public ICacheMonitor getCacheMonitor() - { - return cacheMonitor; - } - - public void setCacheMonitor(ICacheMonitor cacheMonitor) - { - this.cacheMonitor = cacheMonitor; - } - - protected ICacheProbe getCacheProbe() - { - return cacheProbe; - } - - protected ReferenceQueue<E> getReferenceQueue() - { - return referenceQueue; - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (cacheMonitor == null) - { - throw new IllegalStateException("cacheMonitor == null"); - } - } - - @Override - protected void doActivate() throws Exception - { - super.doActivate(); - cacheProbe = cacheMonitor.registerCache(this); - } - - @Override - protected void doDeactivate() throws Exception - { - cacheMonitor.deregisterCache(this); - cacheProbe = null; - super.doDeactivate(); - } - - @Override - protected void work(WorkContext context) throws Exception - { - Reference<? extends E> reference = referenceQueue.remove(200); - if (reference != null) - { - unreachableElement(reference); - } - } - - protected void unreachableElement(Reference<? extends E> reference) - { - E element = reference.get(); - if (element != null) - { - unreachableElement(element); - } - } - - protected void unreachableElement(E element) - { - if (TRACER.isEnabled()) TRACER.trace("Unreachable: " + element); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java deleted file mode 100644 index 36b6337fe2..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java +++ /dev/null @@ -1,242 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.cache; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.event.Event; -import org.eclipse.net4j.internal.util.lifecycle.Worker; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.util.ImplementationError; -import org.eclipse.net4j.util.cache.ICache; -import org.eclipse.net4j.util.cache.ICacheMonitor; -import org.eclipse.net4j.util.cache.ICacheMonitorEvent; -import org.eclipse.net4j.util.cache.ICacheRegistration; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class CacheMonitor extends Worker implements ICacheMonitor -{ - // percentFreeAllocated = Round((freeMemory / totalMemory) * 100); - // percentAllocated = Round((totalMemory / maxMemory ) * 100); - - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CacheMonitor.class); - - private static final long DEFAULT_PAUSE_GREEN = 60L * 1000L; // 1 minute - - private static final long DEFAULT_PAUSE_YELLOW = 5L * 1000L; // 5 seconds - - private static final long DEFAULT_PAUSE_RED = 100L; // 100 milliseconds - - private long pauseGREEN = DEFAULT_PAUSE_GREEN; - - private long pauseYELLOW = DEFAULT_PAUSE_YELLOW; - - private long pauseRED = DEFAULT_PAUSE_RED; - - private ConditionPolicy conditionPolicy; - - private Condition condition; - - private Map<ICache, ICacheRegistration> registrations = new HashMap<ICache, ICacheRegistration>(); - - public CacheMonitor() - { - } - - public long getPauseGREEN() - { - return pauseGREEN; - } - - public void setPauseGREEN(long pauseGREEN) - { - this.pauseGREEN = pauseGREEN; - } - - public long getPauseYELLOW() - { - return pauseYELLOW; - } - - public void setPauseYELLOW(long pauseYELLOW) - { - this.pauseYELLOW = pauseYELLOW; - } - - public long getPauseRED() - { - return pauseRED; - } - - public void setPauseRED(long pauseRED) - { - this.pauseRED = pauseRED; - } - - public ConditionPolicy getConditionPolicy() - { - return conditionPolicy; - } - - public void setConditionPolicy(ConditionPolicy conditionPolicy) - { - this.conditionPolicy = conditionPolicy; - } - - public Condition getCondition() - { - return condition; - } - - public ICacheRegistration[] getRegistrations() - { - synchronized (registrations) - { - return registrations.values().toArray(new ICacheRegistration[registrations.size()]); - } - } - - public ICacheRegistration registerCache(ICache cache) - { - if (TRACER.isEnabled()) TRACER.trace("Registering cache " + cache); - ICacheRegistration registration = new CacheRegistration(this, cache); - ICacheRegistration oldRegistration; - synchronized (registrations) - { - oldRegistration = registrations.put(cache, registration); - } - - if (oldRegistration != null) - { - oldRegistration.dispose(); - } - - return registration; - } - - public void deregisterCache(ICache cache) - { - ICacheRegistration registration; - synchronized (registrations) - { - registration = registrations.remove(cache); - } - - if (registration != null) - { - registration.dispose(); - if (TRACER.isEnabled()) TRACER.trace("Deregistered cache " + cache); - } - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (conditionPolicy == null) - { - throw new IllegalStateException("conditionPolicy == null"); - } - } - - @Override - protected void doDeactivate() throws Exception - { - for (ICacheRegistration registration : getRegistrations()) - { - registration.dispose(); - } - - registrations.clear(); - super.doDeactivate(); - } - - @Override - protected void work(WorkContext context) throws Exception - { - Condition newCondition = conditionPolicy.getNewCondition(condition); - setCondition(newCondition); - - switch (newCondition) - { - case GREEN: - context.nextWork(pauseGREEN); - break; - - case YELLOW: - context.nextWork(pauseYELLOW); - break; - - case RED: - handleConditionRED(); - context.nextWork(pauseRED); - break; - } - } - - protected void setCondition(Condition newCondition) - { - if (newCondition == null) - { - throw new ImplementationError("newCondition == null"); - } - - Condition oldCondition = condition; - if (newCondition != oldCondition) - { - condition = newCondition; - fireEvent(new CacheMonitorEvent(oldCondition, newCondition)); - } - } - - protected void handleConditionRED() - { - System.err.println("CONDITION RED"); - } - - /** - * @author Eike Stepper - */ - private final class CacheMonitorEvent extends Event implements ICacheMonitorEvent - { - private static final long serialVersionUID = 1L; - - private Condition oldCondition; - - private Condition newCondition; - - public CacheMonitorEvent(Condition oldCondition, Condition newCondition) - { - super(CacheMonitor.this); - this.oldCondition = oldCondition; - this.newCondition = newCondition; - } - - public ICacheMonitor getCacheMonitor() - { - return CacheMonitor.this; - } - - public Condition getOldCondition() - { - return oldCondition; - } - - public Condition getNewCondition() - { - return newCondition; - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java deleted file mode 100644 index 5323b42a28..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.cache; - -import org.eclipse.net4j.util.cache.ICache; -import org.eclipse.net4j.util.cache.ICacheMonitor; -import org.eclipse.net4j.util.cache.ICacheRegistration; - -/** - * @author Eike Stepper - */ -public class CacheRegistration implements ICacheRegistration -{ - public static final float DEFAULT_RECONSTRUCTION_COST_DECAY_FACTOR = 0.1f; - - private ICacheMonitor cacheMonitor; - - private ICache cache; - - private int elementCount; - - private long cacheSize; - - private long reconstructionCost; - - public CacheRegistration(ICacheMonitor cacheMonitor, ICache cache) - { - this.cacheMonitor = cacheMonitor; - this.cache = cache; - } - - public void dispose() - { - cacheMonitor = null; - cache = null; - } - - public boolean isDisposed() - { - return cacheMonitor == null || cache == null; - } - - public ICacheMonitor getCacheMonitor() - { - return cacheMonitor; - } - - public ICache getCache() - { - return cache; - } - - public int getElementCount() - { - return elementCount; - } - - public long getCacheSize() - { - return cacheSize; - } - - public long getAverageElementSize() - { - return cacheSize / elementCount; - } - - public long getReconstructionCost() - { - return reconstructionCost; - } - - public void elementCached(int elementSize) - { - checkDisposal(); - ++elementCount; - cacheSize += elementSize; - } - - public void elementEvicted(int elementSize) - { - checkDisposal(); - --elementCount; - cacheSize -= elementSize; - } - - public void elementReconstructed(long reconstructionTime) - { - checkDisposal(); - float decayFactor = getReconstructionCostDecayFactor(); - this.reconstructionCost = (long)(decayFactor * this.reconstructionCost + (1 - decayFactor) * reconstructionTime); - } - - protected float getReconstructionCostDecayFactor() - { - return DEFAULT_RECONSTRUCTION_COST_DECAY_FACTOR; - } - - private void checkDisposal() - { - if (isDisposed()) - { - throw new IllegalStateException("disposed"); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/HysteresisConditionPolicy.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/HysteresisConditionPolicy.java deleted file mode 100644 index 3e420cc455..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/HysteresisConditionPolicy.java +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.cache; - -import org.eclipse.net4j.util.cache.ICacheMonitor.Condition; - -/** - * @author Eike Stepper - */ -public class HysteresisConditionPolicy extends ThresholdConditionPolicy -{ - private long thresholdYellowRed; - - private long thresholdGreenYellow; - - public HysteresisConditionPolicy(long thresholdYellowRed, long thresholdRedYellow, long thresholdGreenYellow, - long thresholdYellowGreen) - { - super(thresholdRedYellow, thresholdYellowGreen); - if (thresholdYellowRed > thresholdRedYellow) - { - throw new IllegalArgumentException("thresholdYellowRed > thresholdRedYellow"); - } - - if (thresholdRedYellow > thresholdGreenYellow) - { - throw new IllegalArgumentException("thresholdRedYellow > thresholdGreenYellow"); - } - - if (thresholdGreenYellow > thresholdYellowGreen) - { - throw new IllegalArgumentException("thresholdGreenYellow > thresholdYellowGreen"); - } - - this.thresholdGreenYellow = thresholdGreenYellow; - this.thresholdYellowRed = thresholdYellowRed; - } - - public long getThresholdYellowRed() - { - return thresholdYellowRed; - } - - public long getThresholdGreenYellow() - { - return thresholdGreenYellow; - } - - @Override - protected Condition getNewCondition(Condition oldCondition, long freeMemory) - { - switch (oldCondition) - { - case GREEN: - if (freeMemory < thresholdYellowRed) - { - return Condition.RED; - } - - if (freeMemory < thresholdGreenYellow) - { - return Condition.YELLOW; - } - - return Condition.GREEN; - - case YELLOW: - if (freeMemory < thresholdYellowRed) - { - return Condition.RED; - } - - if (freeMemory > getThresholdYellowGreen()) - { - return Condition.GREEN; - } - - return Condition.YELLOW; - - case RED: - if (freeMemory > getThresholdYellowGreen()) - { - return Condition.GREEN; - } - - if (freeMemory > getThresholdRedYellow()) - { - return Condition.YELLOW; - } - - return Condition.RED; - - default: - throw new IllegalArgumentException("oldCondition == " + oldCondition); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/ThresholdConditionPolicy.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/ThresholdConditionPolicy.java deleted file mode 100644 index 6342d7159b..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/ThresholdConditionPolicy.java +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.cache; - -import org.eclipse.net4j.util.cache.ICacheMonitor; -import org.eclipse.net4j.util.cache.ICacheMonitor.Condition; - -/** - * @author Eike Stepper - */ -public class ThresholdConditionPolicy implements ICacheMonitor.ConditionPolicy -{ - private long thresholdRedYellow; - - private long thresholdYellowGreen; - - public ThresholdConditionPolicy(long thresholdRedYellow, long thresholdYellowGreen) - { - if (thresholdRedYellow > thresholdYellowGreen) - { - throw new IllegalArgumentException("thresholdRedYellow > thresholdYellowGreen"); - } - - this.thresholdRedYellow = thresholdRedYellow; - this.thresholdYellowGreen = thresholdYellowGreen; - } - - public long getThresholdRedYellow() - { - return thresholdRedYellow; - } - - public long getThresholdYellowGreen() - { - return thresholdYellowGreen; - } - - public Condition getNewCondition(Condition oldCondition) - { - return getNewCondition(oldCondition, Runtime.getRuntime().freeMemory()); - } - - protected Condition getNewCondition(Condition oldCondition, long freeMemory) - { - if (freeMemory > thresholdYellowGreen) - { - return Condition.GREEN; - } - - if (freeMemory > thresholdRedYellow) - { - return Condition.YELLOW; - } - - return Condition.RED; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HashBag.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HashBag.java deleted file mode 100644 index f541ab5676..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HashBag.java +++ /dev/null @@ -1,172 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.collection; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * @author Eike Stepper - */ -public final class HashBag<T> implements Set<T> -{ - private Map<T, HashBag.Counter> map; - - public HashBag() - { - map = new HashMap<T, Counter>(); - } - - public HashBag(int initialCapacity, float loadFactor) - { - map = new HashMap<T, Counter>(initialCapacity, loadFactor); - } - - public HashBag(int initialCapacity) - { - map = new HashMap<T, Counter>(initialCapacity); - } - - public HashBag(Map<? extends T, ? extends HashBag.Counter> m) - { - map = new HashMap<T, Counter>(m); - } - - public boolean add(T o) - { - HashBag.Counter counter = map.get(o); - if (counter == null) - { - counter = new Counter(); - map.put(o, counter); - return true; - } - - counter.incValue(); - return false; - } - - public boolean addAll(Collection<? extends T> c) - { - for (T t : c) - { - add(t); - } - - return true; - } - - public void clear() - { - map.clear(); - } - - public boolean contains(Object o) - { - return map.containsKey(o); - } - - public boolean containsAll(Collection<?> c) - { - return map.keySet().containsAll(c); - } - - public boolean isEmpty() - { - return map.isEmpty(); - } - - public Iterator<T> iterator() - { - return map.keySet().iterator(); - } - - public boolean remove(Object o) - { - HashBag.Counter counter = map.get(o); - if (counter == null) - { - return false; - } - - if (counter.decValue() == 0) - { - map.remove(o); - } - - return true; - } - - public boolean removeAll(Collection<?> c) - { - boolean changed = false; - for (Object object : c) - { - if (remove(object)) - { - changed = true; - } - } - - return changed; - } - - public boolean retainAll(Collection<?> c) - { - throw new UnsupportedOperationException(); - } - - public int size() - { - return map.size(); - } - - public Object[] toArray() - { - return map.keySet().toArray(); - } - - @SuppressWarnings("hiding") - public <T> T[] toArray(T[] a) - { - return map.keySet().toArray(a); - } - - /** - * @author Eike Stepper - */ - private static final class Counter - { - private int value = 1; - - public Counter() - { - } - - public int getValue() - { - return value; - } - - public int incValue() - { - return ++value; - } - - public int decValue() - { - return --value; - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java deleted file mode 100644 index f6d3f61d9a..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/History.java +++ /dev/null @@ -1,214 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.collection; - -import org.eclipse.net4j.internal.util.event.Notifier; -import org.eclipse.net4j.util.collection.IHistory; -import org.eclipse.net4j.util.collection.IHistoryChangeEvent; -import org.eclipse.net4j.util.collection.IHistoryElement; -import org.eclipse.net4j.util.event.INotifier; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class History<T> extends Notifier implements IHistory<T> -{ - protected List<IHistoryElement<T>> elements = new ArrayList<IHistoryElement<T>>(0); - - private boolean loaded; - - public History() - { - } - - public List<IHistoryElement<T>> getElements() - { - lazyLoad(); - return elements; - } - - public void setElements(List<IHistoryElement<T>> newElements) - { - if (newElements == null) - { - newElements = new ArrayList<IHistoryElement<T>>(0); - } - - if (!elements.equals(newElements)) - { - elements = newElements; - changed(); - } - } - - public boolean isEmpty() - { - lazyLoad(); - return elements.isEmpty(); - } - - public int size() - { - lazyLoad(); - return elements.size(); - } - - public int indexOf(T data) - { - lazyLoad(); - for (int i = 0; i < elements.size(); i++) - { - if (elements.get(i).getData().equals(data)) - { - return i; - } - } - - return -1; - } - - public IHistoryElement<T> get(int index) - { - lazyLoad(); - return elements.get(index); - } - - public boolean add(T data) - { - lazyLoad(); - int index = indexOf(data); - IHistoryElement<T> element = index != -1 ? elements.remove(index) : createElement(data); - elements.add(0, element); - - boolean changed = index != 0; - if (changed) - { - changed(); - } - - return changed; - } - - public IHistoryElement<T> remove(int index) - { - lazyLoad(); - IHistoryElement<T> element = elements.remove(index); - if (element != null) - { - changed(); - } - - return element; - } - - public boolean clear() - { - if (elements.isEmpty()) - { - return false; - } - - elements.clear(); - changed(); - return true; - } - - public T getMostRecent() - { - lazyLoad(); - if (isEmpty()) - { - return null; - } - - return elements.get(0).getData(); - } - - @SuppressWarnings("unchecked") - public <D> D[] getData(D[] a) - { - lazyLoad(); - int size = elements.size(); - if (a.length < size) - { - a = (D[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); - } - - for (int i = 0; i < size; i++) - { - a[i] = (D)elements.get(i).getData(); - } - - if (a.length > size) - { - a[size] = null; - } - - return a; - } - - @SuppressWarnings("unchecked") - public IHistoryElement<T>[] toArray() - { - lazyLoad(); - return elements.toArray(new IHistoryElement[elements.size()]); - } - - public Iterator<IHistoryElement<T>> iterator() - { - lazyLoad(); - return elements.iterator(); - } - - @SuppressWarnings("unchecked") - protected IHistoryElement<T> createElement(T data) - { - return new HistoryElement(this, data); - } - - protected void load() - { - } - - protected void save() - { - } - - protected final void changed() - { - save(); - fireChangedEvent(); - } - - private void lazyLoad() - { - if (!loaded) - { - loaded = true; - load(); - } - } - - private void fireChangedEvent() - { - fireEvent(new IHistoryChangeEvent() - { - public INotifier getSource() - { - return History.this; - } - }); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java deleted file mode 100644 index d1759e4343..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/HistoryElement.java +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.collection; - -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.collection.IHistory; -import org.eclipse.net4j.util.collection.IHistoryElement; - -/** - * @author Eike Stepper - */ -public class HistoryElement<T> implements IHistoryElement<T> -{ - private IHistory<IHistoryElement<T>> history; - - private T data; - - public HistoryElement(IHistory<IHistoryElement<T>> history, T data) - { - this.history = history; - this.data = data; - } - - public IHistory<IHistoryElement<T>> getHistory() - { - return history; - } - - public T getData() - { - return data; - } - - public String getText() - { - return data.toString(); - } - - @SuppressWarnings("unchecked") - @Override - public boolean equals(Object obj) - { - if (obj == this) - { - return true; - } - - if (obj instanceof IHistoryElement) - { - IHistoryElement<T> that = (IHistoryElement<T>)obj; - return ObjectUtil.equals(history, that.getHistory()) && ObjectUtil.equals(data, that.getData()); - } - - return false; - } - - @Override - public int hashCode() - { - return history.hashCode() ^ data.hashCode(); - } - - @Override - public String toString() - { - return getText(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/MoveableArrayList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/MoveableArrayList.java deleted file mode 100644 index b17f949865..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/MoveableArrayList.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.eclipse.net4j.internal.util.collection; - -import org.eclipse.net4j.util.collection.MoveableList; - -import java.util.ArrayList; - -/** - * A list with O(1) effort for random access. - * - * @author Eike Stepper - */ -public final class MoveableArrayList<E> extends ArrayList<E> implements MoveableList<E> -{ - private static final long serialVersionUID = 1L; - - public MoveableArrayList(int initialCapacity) - { - super(initialCapacity); - - } - - public E move(int targetIndex, int sourceIndex) - { - int size = size(); - if (sourceIndex >= size) - { - throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + size); - } - - if (targetIndex >= size) - { - throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + size); - } - - E object = get(sourceIndex); - if (targetIndex == sourceIndex) - { - return object; - } - - if (targetIndex < sourceIndex) - { - moveUp1(targetIndex, sourceIndex - targetIndex); - } - else - { - moveDown1(targetIndex, targetIndex - sourceIndex); - } - - set(targetIndex, object); - return object; - } - - private void moveUp1(int index, int count) - { - for (int i = count; i > 0; i--) - { - set(index + i, get(index + i - 1)); - } - } - - private void moveDown1(int index, int count) - { - for (int i = count; i > 0; i--) - { - set(index - i, get(index - i + 1)); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java deleted file mode 100644 index 70676982c9..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/collection/PreferenceHistory.java +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.collection; - -import org.eclipse.net4j.util.collection.IHistoryElement; -import org.eclipse.net4j.util.om.pref.OMPreference; - -/** - * @author Eike Stepper - */ -public class PreferenceHistory extends History<String> -{ - private OMPreference<String[]> preference; - - public PreferenceHistory(OMPreference<String[]> preference) - { - this.preference = preference; - } - - public OMPreference<String[]> getPreference() - { - return preference; - } - - @Override - protected void load() - { - String[] value = preference.getValue(); - for (String data : value) - { - IHistoryElement<String> element = createElement(data); - elements.add(element); - } - } - - @Override - protected void save() - { - String[] array = getData(new String[size()]); - preference.setValue(array); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java deleted file mode 100644 index b75f513572..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java +++ /dev/null @@ -1,162 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.util.concurrent.IWorkSerializer; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutorService; - -/** - * @author Eike Stepper - */ -public class AsynchronousWorkSerializer implements IWorkSerializer, Runnable -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONCURRENCY, AsynchronousWorkSerializer.class); - - private ExecutorService executorService; - - private Queue<Runnable> workQueue; - - private Occupation occupation = new Occupation(); - - // private Object newElementLock = new Object(); - - public AsynchronousWorkSerializer(ExecutorService executorService, Queue<Runnable> workQueue) - { - if (executorService == null) - { - throw new IllegalArgumentException("executorService == null"); //$NON-NLS-1$ - } - - this.executorService = executorService; - this.workQueue = workQueue; - } - - public AsynchronousWorkSerializer(ExecutorService executorService) - { - this(executorService, new ConcurrentLinkedQueue<Runnable>()); - } - - public ExecutorService getExecutorService() - { - return executorService; - } - - public boolean addWork(Runnable work) - { - // Need to be a block of execution. Cannot add when doing last check - // XXX synchronized (newElementLock) - { - workQueue.add(work); - - // isOccupied can (and must) be called unsynchronized here - if (!occupation.isOccupied()) - { - synchronized (occupation) - { - occupation.setOccupied(true); - } - - if (TRACER.isEnabled()) - { - TRACER.trace("Notifying executor service"); //$NON-NLS-1$ - } - - executorService.execute(this); - } - } - - return true; - } - - /** - * Executed in the context of the {@link #getExecutorService() executor service}. - * <p> - */ - public void run() - { - // XXX synchronized (occupation) - { - Runnable work; - // for (;;) - { - while (occupation.isOccupied() && (work = workQueue.poll()) != null) - { - try - { - work.run(); - } - catch (RuntimeException ex) - { - if (TRACER.isEnabled()) - { - TRACER.trace(ex); - } - } - } - - // ConcurrencyUtil.sleep(500); - - // Could put the sync in the while loop... but not efficient. - // Doing a last check to make sure that no one added something in the - // queue - // synchronized (newElementLock) - // { - // if (!occupation.isOccupied() || (work = workQueue.peek()) == null) - // { - // occupation.setOccupied(false); - // break; - // } - // } - } - } - } - - public void dispose() - { - if (occupation.isOccupied()) - { - occupation.setOccupied(false); - } - - workQueue.clear(); - workQueue = null; - executorService = null; - } - - @Override - public String toString() - { - return AsynchronousWorkSerializer.class.getSimpleName(); - } - - /** - * @author Eike Stepper - */ - private static final class Occupation - { - private boolean occupied = false; - - public boolean isOccupied() - { - return occupied; - } - - public void setOccupied(boolean occupied) - { - this.occupied = occupied; - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/CompletionWorkSerializer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/CompletionWorkSerializer.java deleted file mode 100644 index 4fa6541818..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/CompletionWorkSerializer.java +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.util.concurrent.IWorkSerializer; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletionService; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.Future; - -/** - * @author Eike Stepper - */ -public class CompletionWorkSerializer implements IWorkSerializer -{ - private CompletionService<Object> completionService; - - public CompletionWorkSerializer(CompletionService<Object> completionService) - { - this.completionService = completionService; - } - - public CompletionWorkSerializer(Executor executor, BlockingQueue<Future<Object>> completionQueue) - { - this(new ExecutorCompletionService<Object>(executor, completionQueue)); - } - - public CompletionWorkSerializer(Executor executor) - { - this(new ExecutorCompletionService<Object>(executor)); - } - - public CompletionWorkSerializer() - { - this(new OnePendingExecutor()); - } - - public CompletionService<Object> getCompletionService() - { - return completionService; - } - - public void dispose() - { - } - - public boolean addWork(Runnable work) - { - completionService.submit(work, true); - return true; - } - - @Override - public String toString() - { - return CompletionWorkSerializer.class.getSimpleName(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/OnePendingExecutor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/OnePendingExecutor.java deleted file mode 100644 index 30be501195..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/OnePendingExecutor.java +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import java.util.concurrent.Executor; - -public class OnePendingExecutor implements Executor -{ - private Runnable command; - - private Thread thread; - - public OnePendingExecutor() - { - } - - public synchronized void execute(Runnable command) - { - if (this.command != null) - { - throw new IllegalStateException("One command already pending"); - } - - this.command = command; - if (thread == null) - { - thread = new Thread() - { - @Override - public void run() - { - for (;;) - { - Runnable command; - synchronized (OnePendingExecutor.this) - { - if (OnePendingExecutor.this.command == null) - { - thread = null; - return; - } - - command = OnePendingExecutor.this.command; - OnePendingExecutor.this.command = null; - } - - command.run(); - } - } - }; - - thread.setDaemon(true); - thread.start(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/QueueWorkerWorkSerializer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/QueueWorkerWorkSerializer.java deleted file mode 100644 index 6a1c2b6dc3..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/QueueWorkerWorkSerializer.java +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.internal.util.lifecycle.QueueWorker; -import org.eclipse.net4j.util.concurrent.IWorkSerializer; - -/** - * @author Eike Stepper - */ -public class QueueWorkerWorkSerializer extends QueueWorker<Runnable> implements IWorkSerializer -{ - public QueueWorkerWorkSerializer() - { - activate(); - } - - public void dispose() - { - deactivate(); - } - - @Override - protected void work(WorkContext context, Runnable element) - { - element.run(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/ResultSynchronizer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/ResultSynchronizer.java deleted file mode 100644 index 48e9010856..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/ResultSynchronizer.java +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.util.concurrent.ISynchronizer; -import org.eclipse.net4j.util.om.monitor.MonitorUtil; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * @author Eike Stepper - */ -public final class ResultSynchronizer<RESULT> implements ISynchronizer<RESULT> -{ - private RESULT result; - - private Object consumerLock = new Object(); - - private CountDownLatch producerLatch = new CountDownLatch(1); - - public ResultSynchronizer() - { - } - - public RESULT get(long timeout) - { - try - { - final long stop = System.currentTimeMillis() + timeout; - synchronized (consumerLock) - { - while (result == null) - { - try - { - final long remaining = stop - System.currentTimeMillis(); - if (remaining <= 0) - { - return null; - } - - if (MonitorUtil.isCanceled()) - { - return null; - } - - consumerLock.wait(Math.min(remaining, 100L)); - } - catch (InterruptedException ex) - { - return null; - } - } - - return result; - } - } - finally - { - producerLatch.countDown(); - } - } - - public void put(RESULT result) - { - synchronized (consumerLock) - { - this.result = result; - consumerLock.notifyAll(); - } - } - - public boolean put(RESULT result, long timeout) - { - synchronized (consumerLock) - { - this.result = result; - consumerLock.notifyAll(); - } - - try - { - if (!producerLatch.await(timeout, TimeUnit.MILLISECONDS)) - { - return false; - } - } - catch (InterruptedException ex) - { - return false; - } - - return true; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/RoundRobinList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/RoundRobinList.java deleted file mode 100644 index cdf7235904..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/RoundRobinList.java +++ /dev/null @@ -1,512 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * @author Eike Stepper - */ -public final class RoundRobinList<E> extends LinkedList<E> -{ - private static final long serialVersionUID = 1L; - - private ReadWriteLock lock = new ReentrantReadWriteLock(); - - private Iterator<E> it; - - public RoundRobinList() - { - } - - public RoundRobinList(Collection<? extends E> c) - { - super(c); - } - - public void executeReads(Runnable runnable) - { - try - { - lock.readLock().lock(); - runnable.run(); - } - finally - { - lock.readLock().unlock(); - } - } - - public void executeWrites(Runnable runnable) - { - try - { - lock.writeLock().lock(); - runnable.run(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public void add(int index, E element) - { - try - { - lock.writeLock().lock(); - super.add(index, element); - it = null; - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean add(E o) - { - try - { - lock.writeLock().lock(); - it = null; - return super.add(o); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean addAll(Collection<? extends E> c) - { - try - { - lock.writeLock().lock(); - it = null; - return super.addAll(c); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean addAll(int index, Collection<? extends E> c) - { - try - { - lock.writeLock().lock(); - it = null; - return super.addAll(index, c); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public void addFirst(E o) - { - try - { - lock.writeLock().lock(); - it = null; - super.addFirst(o); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public void addLast(E o) - { - try - { - lock.writeLock().lock(); - it = null; - super.addLast(o); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public void clear() - { - try - { - lock.writeLock().lock(); - it = null; - super.clear(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public Object clone() - { - try - { - lock.readLock().lock(); - return super.clone(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public boolean contains(Object o) - { - try - { - lock.readLock().lock(); - return super.contains(o); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public boolean containsAll(Collection<?> c) - { - try - { - lock.readLock().lock(); - return super.containsAll(c); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public E element() - { - try - { - lock.readLock().lock(); - if (isEmpty()) - { - return null; - } - - if (it == null || !it.hasNext()) - { - it = iterator(); - } - - return it.next(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public E get(int index) - { - try - { - lock.readLock().lock(); - return super.get(index); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public E getFirst() - { - try - { - lock.readLock().lock(); - return super.getFirst(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public E getLast() - { - try - { - lock.readLock().lock(); - return super.getLast(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public int indexOf(Object o) - { - try - { - lock.readLock().lock(); - return super.indexOf(o); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public int lastIndexOf(Object o) - { - try - { - lock.readLock().lock(); - return super.lastIndexOf(o); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public boolean offer(E o) - { - try - { - lock.writeLock().lock(); - it = null; - return super.offer(o); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E peek() - { - try - { - lock.readLock().lock(); - return super.peek(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public E poll() - { - try - { - lock.writeLock().lock(); - it = null; - return super.poll(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E remove() - { - try - { - lock.writeLock().lock(); - it = null; - return super.remove(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E remove(int index) - { - try - { - lock.writeLock().lock(); - it = null; - return super.remove(index); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean remove(Object o) - { - try - { - lock.writeLock().lock(); - it = null; - return super.remove(o); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean removeAll(Collection<?> c) - { - try - { - lock.writeLock().lock(); - it = null; - return super.removeAll(c); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E removeFirst() - { - try - { - lock.writeLock().lock(); - it = null; - return super.removeFirst(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E removeLast() - { - try - { - lock.writeLock().lock(); - it = null; - return super.removeLast(); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public boolean retainAll(Collection<?> c) - { - try - { - lock.writeLock().lock(); - it = null; - return super.retainAll(c); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public E set(int index, E element) - { - try - { - lock.writeLock().lock(); - it = null; - return super.set(index, element); - } - finally - { - lock.writeLock().unlock(); - } - } - - @Override - public List<E> subList(int fromIndex, int toIndex) - { - try - { - lock.readLock().lock(); - return super.subList(fromIndex, toIndex); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public Object[] toArray() - { - try - { - lock.readLock().lock(); - return super.toArray(); - } - finally - { - lock.readLock().unlock(); - } - } - - @Override - public <T> T[] toArray(T[] a) - { - try - { - lock.readLock().lock(); - return super.toArray(a); - } - finally - { - lock.readLock().unlock(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronizingCorrelator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronizingCorrelator.java deleted file mode 100644 index 31d26540d9..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronizingCorrelator.java +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.util.concurrent.ICorrelator; -import org.eclipse.net4j.util.concurrent.ISynchronizer; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * @author Eike Stepper - */ -public class SynchronizingCorrelator<CORRELATION, RESULT> implements ICorrelator<CORRELATION, ISynchronizer<RESULT>> -{ - private ConcurrentMap<CORRELATION, ISynchronizer<RESULT>> map = new ConcurrentHashMap<CORRELATION, ISynchronizer<RESULT>>( - 0); - - public boolean isCorrelated(CORRELATION correlation) - { - return map.containsKey(correlation); - } - - public ISynchronizer<RESULT> correlate(CORRELATION correlation) - { - ISynchronizer<RESULT> synchronizer = map.get(correlation); - if (synchronizer == null) - { - synchronizer = createSynchronizer(correlation); - map.put(correlation, synchronizer); - } - - return synchronizer; - } - - public ISynchronizer<RESULT> correlateUnique(CORRELATION correlation) - { - ISynchronizer<RESULT> synchronizer = createSynchronizer(correlation); - if (map.putIfAbsent(correlation, synchronizer) != null) - { - throw new IllegalStateException("Already correlated: " + correlation); //$NON-NLS-1$ - } - - return synchronizer; - } - - public ISynchronizer<RESULT> uncorrelate(CORRELATION correlation) - { - return map.remove(correlation); - } - - public RESULT get(CORRELATION correlation, long timeout) - { - return correlate(correlation).get(timeout); - } - - public void put(CORRELATION correlation, RESULT result) - { - correlate(correlation).put(result); - } - - public boolean put(CORRELATION correlation, RESULT result, long timeout) - { - return correlate(correlation).put(result, timeout); - } - - protected ISynchronizer<RESULT> createSynchronizer(final CORRELATION correlation) - { - // TODO Make top level class - return new ISynchronizer<RESULT>() - { - private ISynchronizer<RESULT> delegate = new ResultSynchronizer<RESULT>(); - - public RESULT get(long timeout) - { - RESULT result = delegate.get(timeout); - uncorrelate(correlation); - return result; - } - - public void put(RESULT result) - { - delegate.put(result); - } - - public boolean put(RESULT result, long timeout) - { - return delegate.put(result, timeout); - } - }; - } - - @Override - public String toString() - { - return "SynchronizingCorrelator" + map; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronousWorkSerializer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronousWorkSerializer.java deleted file mode 100644 index dbebe7bf8f..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/SynchronousWorkSerializer.java +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.concurrent; - -import org.eclipse.net4j.util.concurrent.IWorkSerializer; - -/** - * @author Eike Stepper - */ -public class SynchronousWorkSerializer implements IWorkSerializer -{ - public SynchronousWorkSerializer() - { - } - - public boolean addWork(Runnable work) - { - work.run(); - return true; - } - - public void dispose() - { - } - - @Override - public String toString() - { - return SynchronousWorkSerializer.class.getSimpleName(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/Container.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/Container.java deleted file mode 100644 index f94f5dfc0e..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/Container.java +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.internal.util.lifecycle.Lifecycle; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerDelta.Kind; - -import java.util.List; - -/** - * @author Eike Stepper - */ -public abstract class Container<E> extends Lifecycle implements IContainer<E> -{ - public Container() - { - } - - public boolean isEmpty() - { - E[] elements = getElements(); - return elements == null || elements.length == 0; - } - - public void fireElementAddedEvent(E element) - { - fireContainerEvent(element, IContainerDelta.Kind.ADDED); - } - - public void fireElementRemovedEvent(E element) - { - fireContainerEvent(element, IContainerDelta.Kind.REMOVED); - } - - public void fireContainerEvent(E element, Kind kind) - { - fireEvent(newContainerEvent(element, kind)); - } - - public void fireContainerEvent(List<IContainerDelta<E>> deltas) - { - fireEvent(new ContainerEvent<E>(this, deltas)); - } - - protected SingleDeltaContainerEvent<E> newContainerEvent(E element, Kind kind) - { - return new SingleDeltaContainerEvent<E>(this, element, kind); - } - - protected ContainerEvent<E> newContainerEvent() - { - return new ContainerEvent<E>(this); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerDelta.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerDelta.java deleted file mode 100644 index 4889bb8164..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerDelta.java +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.util.container.IContainerDelta; - -/** - * @author Eike Stepper - */ -public class ContainerDelta<E> implements IContainerDelta<E> -{ - private E element; - - private Kind kind; - - public ContainerDelta(E element, Kind kind) - { - this.element = element; - this.kind = kind; - } - - public E getElement() - { - return element; - } - - public E setValue(E value) - { - throw new UnsupportedOperationException(); - } - - public Kind getKind() - { - return kind; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEvent.java deleted file mode 100644 index af80c3f59e..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEvent.java +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.internal.util.event.Event; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IContainerEventVisitor; -import org.eclipse.net4j.util.container.IContainerDelta.Kind; -import org.eclipse.net4j.util.container.IContainerEventVisitor.Filtered; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class ContainerEvent<E> extends Event implements IContainerEvent<E> -{ - private static final long serialVersionUID = 1L; - - private List<IContainerDelta<E>> deltas; - - public ContainerEvent(IContainer<E> container) - { - super(container); - deltas = new ArrayList<IContainerDelta<E>>(); - } - - public ContainerEvent(IContainer<E> container, List<IContainerDelta<E>> deltas) - { - super(container); - this.deltas = deltas; - } - - @SuppressWarnings("unchecked") - public IContainer<E> getContainer() - { - return (IContainer<E>)getSource(); - } - - public boolean isEmpty() - { - return deltas.isEmpty(); - } - - @SuppressWarnings("unchecked") - public IContainerDelta<E>[] getDeltas() - { - return deltas.toArray(new IContainerDelta[deltas.size()]); - } - - public IContainerDelta<E> getDelta() throws IllegalStateException - { - if (deltas.size() != 1) - { - throw new IllegalStateException("deltas.size() != 1"); - } - - return deltas.get(0); - } - - public E getDeltaElement() throws IllegalStateException - { - return getDelta().getElement(); - } - - public Kind getDeltaKind() throws IllegalStateException - { - return getDelta().getKind(); - } - - public void addDelta(E element, Kind kind) - { - addDelta(new ContainerDelta<E>(element, kind)); - } - - public void addDelta(IContainerDelta<E> delta) - { - deltas.add(delta); - } - - public void accept(IContainerEventVisitor<E> visitor) - { - for (IContainerDelta<E> delta : deltas) - { - E element = delta.getElement(); - - boolean filtered = true; - if (visitor instanceof Filtered) - { - filtered = ((Filtered<E>)visitor).filter(element); - } - - if (filtered) - { - switch (delta.getKind()) - { - case ADDED: - visitor.added(element); - break; - case REMOVED: - visitor.removed(element); - break; - } - } - } - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - for (IContainerDelta<E> delta : getDeltas()) - { - builder.append(", "); - builder.append(delta.getKind()); - builder.append("="); - builder.append(delta.getElement()); - } - - return MessageFormat.format("ContainerEvent[source={0}{1}]", getSource(), builder.toString()); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEventAdapter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEventAdapter.java deleted file mode 100644 index cb2b42e3c8..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ContainerEventAdapter.java +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IContainerEventVisitor; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; - -/** - * @author Eike Stepper - */ -public class ContainerEventAdapter<E> implements IListener -{ - public ContainerEventAdapter() - { - } - - @SuppressWarnings("unchecked") - public final void notifyEvent(IEvent event) - { - if (event instanceof IContainerEvent) - { - IContainerEvent<E> e = (IContainerEvent<E>)event; - notifyContainerEvent(e); - } - else - { - notifyOtherEvent(event); - } - } - - protected void notifyContainerEvent(IContainerEvent<E> event) - { - final IContainer<E> container = event.getContainer(); - event.accept(new IContainerEventVisitor<E>() - { - public void added(E element) - { - onAdded(container, element); - } - - public void removed(E element) - { - onRemoved(container, element); - } - }); - } - - protected void notifyOtherEvent(IEvent event) - { - } - - protected void onAdded(IContainer<E> container, E element) - { - } - - protected void onRemoved(IContainer<E> container, E element) - { - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/LifecycleEventConverter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/LifecycleEventConverter.java deleted file mode 100644 index 0ae34b5c92..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/LifecycleEventConverter.java +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.internal.util.event.Notifier; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IContainerDelta.Kind; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.event.INotifier; -import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; - -/** - * Is registered with each {@link IChannel} of this {@link IConnector}. - * <p> - * - * @author Eike Stepper - */ -public class LifecycleEventConverter<E> implements IListener -{ - private Notifier owner; - - public LifecycleEventConverter(Notifier owner) - { - this.owner = owner; - } - - public INotifier getOwner() - { - return owner; - } - - public void notifyEvent(IEvent event) - { - if (event instanceof ILifecycleEvent) - { - ILifecycleEvent e = (ILifecycleEvent)event; - switch (e.getKind()) - { - case ACTIVATED: - added(e); - break; - - case DEACTIVATED: - removed(e); - break; - } - } - } - - protected void added(ILifecycleEvent e) - { - fireContainerEvent(e, IContainerDelta.Kind.ADDED); - } - - protected void removed(ILifecycleEvent e) - { - fireContainerEvent(e, IContainerDelta.Kind.REMOVED); - } - - @SuppressWarnings("unchecked") - protected void fireContainerEvent(ILifecycleEvent e, IContainerDelta.Kind kind) - { - E element = (E)e.getLifecycle(); - if (element != null) - { - IContainerEvent<E> event = createContainerEvent((IContainer<E>)owner, element, kind); - owner.fireEvent(event); - } - } - - protected IContainerEvent<E> createContainerEvent(IContainer<E> container, E element, Kind kind) - { - ContainerEvent<E> event = new ContainerEvent<E>(container); - event.addDelta(new ContainerDelta<E>(element, kind)); - return event; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ManagedContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ManagedContainer.java deleted file mode 100644 index a83ab176a5..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/ManagedContainer.java +++ /dev/null @@ -1,559 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.factory.FactoryKey; -import org.eclipse.net4j.internal.util.lifecycle.Lifecycle; -import org.eclipse.net4j.internal.util.lifecycle.LifecycleEventAdapter; -import org.eclipse.net4j.internal.util.registry.HashMapRegistry; -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.container.FactoryNotFoundException; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IElementProcessor; -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.event.EventUtil; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.factory.IFactory; -import org.eclipse.net4j.util.factory.IFactoryKey; -import org.eclipse.net4j.util.lifecycle.ILifecycle; -import org.eclipse.net4j.util.lifecycle.LifecycleUtil; -import org.eclipse.net4j.util.registry.IRegistry; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Map.Entry; - -/** - * @author Eike Stepper - */ -public class ManagedContainer extends Lifecycle implements IManagedContainer -{ - private IRegistry<IFactoryKey, IFactory> factoryRegistry; - - private List<IElementProcessor> postProcessors; - - private IRegistry<ElementKey, Object> elementRegistry = new HashMapRegistry<ElementKey, Object>(); - - private long maxElementID; - - private IListener elementListener = new LifecycleEventAdapter() - { - @Override - protected void onDeactivated(ILifecycle lifecycle) - { - for (Entry<ElementKey, Object> entry : elementRegistry.entrySet()) - { - if (lifecycle == entry.getValue()) - { - removeElement(entry.getKey()); - return; - } - } - } - }; - - public ManagedContainer() - { - } - - public synchronized IRegistry<IFactoryKey, IFactory> getFactoryRegistry() - { - if (factoryRegistry == null) - { - factoryRegistry = createFactoryRegistry(); - } - - return factoryRegistry; - } - - public ManagedContainer registerFactory(IFactory factory) - { - getFactoryRegistry().put(factory.getKey(), factory); - return this; - } - - public synchronized List<IElementProcessor> getPostProcessors() - { - if (postProcessors == null) - { - postProcessors = createPostProcessors(); - } - - return postProcessors; - } - - public synchronized void addPostProcessor(IElementProcessor postProcessor, boolean processExistingElements) - { - if (processExistingElements) - { - ContainerEvent<Object> event = new ContainerEvent<Object>(this); - for (Entry<ElementKey, Object> entry : elementRegistry.entrySet()) - { - ElementKey key = entry.getKey(); - Object element = entry.getValue(); - - String productGroup = key.getProductGroup(); - String factoryType = key.getFactoryType(); - String description = key.getDescription(); - Object newElement = postProcessor.process(this, productGroup, factoryType, description, element); - if (newElement != element) - { - elementRegistry.put(key, newElement); - event.addDelta(element, IContainerDelta.Kind.REMOVED); - event.addDelta(newElement, IContainerDelta.Kind.ADDED); - } - } - - fireEvent(event); - } - - getPostProcessors().add(postProcessor); - } - - public void addPostProcessor(IElementProcessor postProcessor) - { - getPostProcessors().add(postProcessor); - } - - public void removePostProcessor(IElementProcessor postProcessor) - { - getPostProcessors().remove(postProcessor); - } - - public Set<String> getProductGroups() - { - Set<String> result = new HashSet<String>(); - for (IFactoryKey key : factoryRegistry.keySet()) - { - result.add(key.getProductGroup()); - } - - for (ElementKey key : elementRegistry.keySet()) - { - result.add(key.getProductGroup()); - } - - return result; - } - - public Set<String> getFactoryTypes(String productGroup) - { - Set<String> result = new HashSet<String>(); - for (IFactoryKey key : factoryRegistry.keySet()) - { - if (ObjectUtil.equals(key.getProductGroup(), productGroup)) - { - result.add(key.getType()); - } - } - - for (ElementKey key : elementRegistry.keySet()) - { - if (ObjectUtil.equals(key.getProductGroup(), productGroup)) - { - result.add(key.getFactoryType()); - } - } - - return result; - } - - public IFactory getFactory(String productGroup, String factoryType) - { - FactoryKey key = new FactoryKey(productGroup, factoryType); - IFactory factory = getFactoryRegistry().get(key); - if (factory == null) - { - throw new FactoryNotFoundException("Factory not found: " + key); - } - - return factory; - } - - public boolean isEmpty() - { - return elementRegistry.isEmpty(); - } - - public String[] getElementKey(Object element) - { - for (Entry<ElementKey, Object> entry : elementRegistry.entrySet()) - { - if (entry.getValue() == element) - { - ElementKey key = entry.getKey(); - String[] result = { key.getProductGroup(), key.getFactoryType(), key.getDescription() }; - return result; - } - } - - return null; - } - - public Object[] getElements() - { - return elementRegistry.values().toArray(); - } - - public Object[] getElements(String productGroup) - { - List<Object> result = new ArrayList<Object>(); - for (Entry<ElementKey, Object> entry : elementRegistry.entrySet()) - { - ElementKey key = entry.getKey(); - if (ObjectUtil.equals(key.getProductGroup(), productGroup)) - { - result.add(entry.getValue()); - } - } - - return result.toArray(); - } - - public Object[] getElements(String productGroup, String factoryType) - { - List<Object> result = new ArrayList<Object>(); - for (Entry<ElementKey, Object> entry : elementRegistry.entrySet()) - { - ElementKey key = entry.getKey(); - if (ObjectUtil.equals(key.getProductGroup(), productGroup) - && ObjectUtil.equals(key.getFactoryType(), factoryType)) - { - result.add(entry.getValue()); - } - } - - return result.toArray(); - } - - public Object getElement(String productGroup, String factoryType, String description) - { - ElementKey key = new ElementKey(productGroup, factoryType, description); - Object element = elementRegistry.get(key); - if (element == null) - { - element = createElement(productGroup, factoryType, description); - element = postProcessElement(productGroup, factoryType, description, element); - LifecycleUtil.activate(element); - putElement(key, element); - } - - return element; - } - - public Object putElement(String productGroup, String factoryType, String description, Object element) - { - ElementKey key = new ElementKey(productGroup, factoryType, description); - return putElement(key, element); - } - - protected Object putElement(ElementKey key, Object element) - { - ContainerEvent<Object> event = new ContainerEvent<Object>(this); - key.setID(++maxElementID); - Object oldElement = elementRegistry.put(key, element); - if (oldElement != null) - { - EventUtil.removeListener(oldElement, elementListener); - event.addDelta(oldElement, IContainerDelta.Kind.REMOVED); - } - - event.addDelta(element, IContainerDelta.Kind.ADDED); - fireEvent(event); - EventUtil.addListener(element, elementListener); - return oldElement; - } - - public Object removeElement(String productGroup, String factoryType, String description) - { - ElementKey key = new ElementKey(productGroup, factoryType, description); - return removeElement(key); - } - - protected Object removeElement(ElementKey key) - { - Object element = elementRegistry.remove(key); - if (element != null) - { - EventUtil.removeListener(element, elementListener); - fireEvent(new SingleDeltaContainerEvent<Object>(this, element, IContainerDelta.Kind.REMOVED)); - } - - return element; - } - - public void clearElements() - { - if (!elementRegistry.isEmpty()) - { - ContainerEvent<Object> event = new ContainerEvent<Object>(this); - for (Object element : elementRegistry.values()) - { - EventUtil.removeListener(element, elementListener); - event.addDelta(element, IContainerDelta.Kind.REMOVED); - } - - elementRegistry.clear(); - fireEvent(event); - } - } - - public void loadElements(InputStream stream) throws IOException - { - clearElements(); - ObjectInputStream ois = new ObjectInputStream(stream); - int size = ois.readInt(); - for (int i = 0; i < size; i++) - { - try - { - ElementKey key = (ElementKey)ois.readObject(); - Object element = getElement(key.getProductGroup(), key.getFactoryType(), key.getDescription()); - - boolean active = ois.readBoolean(); - if (active) - { - // TODO Reconsider activation - LifecycleUtil.activate(element); - } - } - catch (ClassNotFoundException cannotHappen) - { - } - } - - initMaxElementID(); - } - - public void saveElements(OutputStream stream) throws IOException - { - ObjectOutputStream oos = new ObjectOutputStream(stream); - List<Entry<ElementKey, Object>> entries = new ArrayList<Entry<ElementKey, Object>>(elementRegistry.entrySet()); - Collections.sort(entries, new EntryComparator()); - - oos.writeInt(entries.size()); - for (Entry<ElementKey, Object> entry : entries) - { - oos.writeObject(entry.getKey()); - oos.writeBoolean(LifecycleUtil.isActive(entry.getValue())); - } - } - - @SuppressWarnings("unchecked") - @Override - public void fireEvent(IEvent event) - { - if (event instanceof IContainerEvent) - { - IContainerEvent<Object> containerEvent = (IContainerEvent<Object>)event; - if (containerEvent.isEmpty()) - { - return; - } - } - - super.fireEvent(event); - } - - @Override - public String toString() - { - return "ManagedContainer"; - } - - protected IRegistry<IFactoryKey, IFactory> createFactoryRegistry() - { - return new HashMapRegistry<IFactoryKey, IFactory>(); - } - - protected List<IElementProcessor> createPostProcessors() - { - return new ArrayList<IElementProcessor>(); - } - - protected Object createElement(String productGroup, String factoryType, String description) - { - IFactory factory = getFactory(productGroup, factoryType); - return factory.create(description); - } - - protected Object postProcessElement(String productGroup, String factoryType, String description, Object element) - { - for (IElementProcessor processor : getPostProcessors()) - { - element = processor.process(this, productGroup, factoryType, description, element); - } - - return element; - } - - protected void initMaxElementID() - { - maxElementID = 0L; - for (ElementKey key : elementRegistry.keySet()) - { - long id = key.getID(); - if (maxElementID < id) - { - maxElementID = id; - } - } - } - - @Override - protected void doActivate() throws Exception - { - super.doActivate(); - LifecycleUtil.activate(getFactoryRegistry()); - LifecycleUtil.activate(getPostProcessors()); - } - - @Override - protected void doDeactivate() throws Exception - { - Collection<Object> values = elementRegistry.values(); - for (Object element : values.toArray()) - { - try - { - LifecycleUtil.deactivateNoisy(element); - EventUtil.removeListener(element, elementListener); - } - catch (RuntimeException ex) - { - OM.LOG.warn(ex); - } - } - - LifecycleUtil.deactivate(factoryRegistry); - LifecycleUtil.deactivate(postProcessors); - super.doDeactivate(); - } - - /** - * @author Eike Stepper - */ - private static final class ElementKey implements Serializable, Comparable<ElementKey> - { - private static final long serialVersionUID = 1L; - - private long id; - - private String productGroup; - - private String factoryType; - - private String description; - - public ElementKey(String productGroup, String factoryType, String description) - { - this.productGroup = productGroup; - this.factoryType = factoryType; - this.description = description; - } - - public long getID() - { - return id; - } - - public void setID(long id) - { - this.id = id; - } - - public String getProductGroup() - { - return productGroup; - } - - public String getFactoryType() - { - return factoryType; - } - - public String getDescription() - { - return description; - } - - @Override - public boolean equals(Object obj) - { - if (obj == this) - { - return true; - } - - if (obj instanceof ElementKey) - { - ElementKey key = (ElementKey)obj; - return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(factoryType, key.factoryType) - && ObjectUtil.equals(description, key.description); - } - - return false; - } - - @Override - public int hashCode() - { - return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(factoryType) ^ ObjectUtil.hashCode(description); - } - - @Override - public String toString() - { - return MessageFormat.format("{0}[{1}, {2}]", productGroup, factoryType, description); - } - - public int compareTo(ElementKey key) - { - if (id < key.id) - { - return -1; - } - - if (id > key.id) - { - return 1; - } - - return 0; - } - } - - /** - * @author Eike Stepper - */ - private static final class EntryComparator implements Comparator<Entry<ElementKey, Object>> - { - public int compare(Entry<ElementKey, Object> entry1, Entry<ElementKey, Object> entry2) - { - return entry1.getKey().compareTo(entry2.getKey()); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginContainer.java index 0fa7cb7756..3e6435fa86 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginContainer.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginContainer.java @@ -14,6 +14,7 @@ import org.eclipse.net4j.internal.util.bundle.OM; import org.eclipse.net4j.internal.util.factory.PluginFactoryRegistry; import org.eclipse.net4j.util.container.IElementProcessor; import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.net4j.util.container.ManagedContainer; import org.eclipse.net4j.util.factory.IFactory; import org.eclipse.net4j.util.factory.IFactoryKey; import org.eclipse.net4j.util.registry.IRegistry; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java index 0ec19a7e94..af8fd9f07b 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/PluginElementProcessorList.java @@ -11,8 +11,8 @@ package org.eclipse.net4j.internal.util.container; import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.lifecycle.Lifecycle; import org.eclipse.net4j.util.container.IElementProcessor; +import org.eclipse.net4j.util.lifecycle.Lifecycle; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionDelta; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/SingleDeltaContainerEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/SingleDeltaContainerEvent.java deleted file mode 100644 index 0d8127afe7..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/SingleDeltaContainerEvent.java +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container; - -import org.eclipse.net4j.internal.util.event.Event; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IContainerEventVisitor; -import org.eclipse.net4j.util.container.IContainerDelta.Kind; -import org.eclipse.net4j.util.container.IContainerEventVisitor.Filtered; - -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public class SingleDeltaContainerEvent<E> extends Event implements IContainerEvent<E> -{ - private static final long serialVersionUID = 1L; - - private IContainerDelta<E>[] deltas; - - @SuppressWarnings("unchecked") - public SingleDeltaContainerEvent(IContainer<E> container, E element, Kind kind) - { - super(container); - deltas = new IContainerDelta[] { new ContainerDelta<E>(element, kind) }; - } - - @SuppressWarnings("unchecked") - public IContainer<E> getContainer() - { - return (IContainer<E>)getSource(); - } - - public boolean isEmpty() - { - return false; - } - - public IContainerDelta<E>[] getDeltas() - { - return deltas; - } - - public IContainerDelta<E> getDelta() throws IllegalStateException - { - return deltas[0]; - } - - public E getDeltaElement() throws IllegalStateException - { - return deltas[0].getElement(); - } - - public Kind getDeltaKind() throws IllegalStateException - { - return deltas[0].getKind(); - } - - public void accept(IContainerEventVisitor<E> visitor) - { - E element = deltas[0].getElement(); - - boolean filtered = true; - if (visitor instanceof Filtered) - { - filtered = ((Filtered<E>)visitor).filter(element); - } - - if (filtered) - { - switch (deltas[0].getKind()) - { - case ADDED: - visitor.added(element); - break; - case REMOVED: - visitor.removed(element); - break; - } - } - } - - @Override - public String toString() - { - return MessageFormat.format("ContainerEvent[source={0}, {1}={2}]", getSource(), getDeltaElement(), getDeltaKind()); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/AbstractDelegator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/AbstractDelegator.java deleted file mode 100644 index 7be676af7c..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/AbstractDelegator.java +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.internal.util.container.SingleDeltaContainerEvent; -import org.eclipse.net4j.internal.util.event.Notifier; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.IContainerDelta.Kind; - -import java.util.Collection; -import java.util.Iterator; - -/** - * @author Eike Stepper - */ -public abstract class AbstractDelegator<E> extends Notifier implements IContainer<E> -{ - public AbstractDelegator() - { - } - - protected void fireAddedEvent(E o) - { - fireEvent(new SingleDeltaContainerEvent<E>(this, o, IContainerDelta.Kind.ADDED)); - } - - @SuppressWarnings("unchecked") - protected void fireRemovedEvent(Object o) - { - fireEvent(new SingleDeltaContainerEvent<E>(this, (E)o, IContainerDelta.Kind.REMOVED)); - } - - @SuppressWarnings("unchecked") - protected ContainerEvent<E> createEvent(Collection<? super E> c, Kind kind) - { - ContainerEvent<E> event = new ContainerEvent<E>(this); - for (Object o : c) - { - event.addDelta((E)o, kind); - } - - return event; - } - - protected boolean dispatchEvent(ContainerEvent<E> event) - { - if (event.isEmpty()) - { - return false; - } - - fireEvent(event); - return true; - } - - /** - * @author Eike Stepper - */ - public class DelegatingIterator implements Iterator<E> - { - private Iterator<E> delegate; - - protected E last; - - public DelegatingIterator(Iterator<E> delegate) - { - this.delegate = delegate; - } - - public Iterator<E> getDelegate() - { - return delegate; - } - - /** - * @category READ - */ - public boolean hasNext() - { - return getDelegate().hasNext(); - } - - /** - * @category READ - */ - public E next() - { - return last = getDelegate().next(); - } - - /** - * @category WRITE - */ - public void remove() - { - getDelegate().remove(); - fireRemovedEvent(last); - last = null; - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerBlockingQueue.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerBlockingQueue.java deleted file mode 100644 index f2571d25b3..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerBlockingQueue.java +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.delegate.IContainerBlockingQueue; - -import java.util.Collection; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * @author Eike Stepper - */ -public class ContainerBlockingQueue<E> extends ContainerQueue<E> implements IContainerBlockingQueue<E> -{ - public ContainerBlockingQueue(BlockingQueue<E> delegate) - { - super(delegate); - } - - @Override - public BlockingQueue<E> getDelegate() - { - return (BlockingQueue<E>)super.getDelegate(); - } - - /** - * @category WRITE - */ - public int drainTo(Collection<? super E> c) - { - int drainTo = getDelegate().drainTo(c); - ContainerEvent<E> event = createEvent(c, IContainerDelta.Kind.REMOVED); - fireEvent(event); - return drainTo; - } - - /** - * @category WRITE - */ - public int drainTo(Collection<? super E> c, int maxElements) - { - int drainTo = getDelegate().drainTo(c, maxElements); - ContainerEvent<E> event = createEvent(c, IContainerDelta.Kind.REMOVED); - fireEvent(event); - return drainTo; - } - - /** - * @category WRITE - */ - public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException - { - boolean modified = getDelegate().offer(o, timeout, unit); - if (modified) - { - fireAddedEvent(o); - } - - return modified; - } - - /** - * @category WRITE - */ - public E poll(long timeout, TimeUnit unit) throws InterruptedException - { - E removed = getDelegate().poll(timeout, unit); - if (removed != null) - { - fireRemovedEvent(removed); - } - - return removed; - } - - /** - * @category WRITE - */ - public void put(E o) throws InterruptedException - { - getDelegate().put(o); - fireAddedEvent(o); - } - - /** - * @category READ - */ - public int remainingCapacity() - { - return getDelegate().remainingCapacity(); - } - - /** - * @category WRITE - */ - public E take() throws InterruptedException - { - E element = getDelegate().take(); - fireRemovedEvent(element); - return element; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerCollection.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerCollection.java deleted file mode 100644 index 20559fbf4c..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerCollection.java +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.delegate.IContainerCollection; - -import java.util.Collection; -import java.util.Iterator; - -/** - * @author Eike Stepper - */ -public class ContainerCollection<E> extends AbstractDelegator<E> implements IContainerCollection<E> -{ - private Collection<E> delegate; - - public ContainerCollection(Collection<E> delegate) - { - this.delegate = delegate; - } - - public Collection<E> getDelegate() - { - return delegate; - } - - @SuppressWarnings("unchecked") - public E[] getElements() - { - return (E[])toArray(); - } - - /** - * @category WRITE - */ - public boolean add(E o) - { - boolean modified = getDelegate().add(o); - if (modified) - { - fireAddedEvent(o); - } - - return modified; - } - - /** - * @category WRITE - */ - public boolean addAll(Collection<? extends E> c) - { - ContainerEvent<E> event = new ContainerEvent<E>(this); - for (E e : c) - { - boolean modified = getDelegate().add(e); - if (modified) - { - event.addDelta(e, IContainerDelta.Kind.ADDED); - } - } - - return dispatchEvent(event); - } - - /** - * @category WRITE - */ - public void clear() - { - if (!isEmpty()) - { - ContainerEvent<E> event = createEvent(getDelegate(), IContainerDelta.Kind.REMOVED); - getDelegate().clear(); - fireEvent(event); - } - } - - /** - * @category WRITE - */ - public boolean remove(Object o) - { - boolean modified = getDelegate().remove(o); - if (modified) - { - fireRemovedEvent(o); - } - - return modified; - } - - /** - * @category WRITE - */ - @SuppressWarnings("unchecked") - public boolean removeAll(Collection<?> c) - { - ContainerEvent<E> event = new ContainerEvent<E>(this); - for (Object o : c) - { - boolean modified = getDelegate().remove(o); - if (modified) - { - event.addDelta((E)o, IContainerDelta.Kind.REMOVED); - } - } - - return dispatchEvent(event); - } - - /** - * @category WRITE - */ - @SuppressWarnings("unchecked") - public boolean retainAll(Collection<?> c) - { - ContainerEvent<E> event = new ContainerEvent<E>(this); - for (Object o : getDelegate()) - { - if (!c.contains(o)) - { - getDelegate().remove(o); - event.addDelta((E)o, IContainerDelta.Kind.REMOVED); - } - } - - return dispatchEvent(event); - } - - /** - * @category READ - */ - public boolean contains(Object o) - { - return getDelegate().contains(o); - } - - /** - * @category READ - */ - public boolean containsAll(Collection<?> c) - { - return getDelegate().containsAll(c); - } - - /** - * @category READ - */ - @Override - public boolean equals(Object o) - { - return getDelegate().equals(o); - } - - /** - * @category READ - */ - @Override - public int hashCode() - { - return getDelegate().hashCode(); - } - - /** - * @category READ - */ - public boolean isEmpty() - { - return getDelegate().isEmpty(); - } - - /** - * @category READ - */ - public Iterator<E> iterator() - { - return new DelegatingIterator(getDelegate().iterator()); - } - - /** - * @category READ - */ - public int size() - { - return getDelegate().size(); - } - - /** - * @category READ - */ - public Object[] toArray() - { - return getDelegate().toArray(); - } - - /** - * @category READ - */ - public <T> T[] toArray(T[] a) - { - return getDelegate().toArray(a); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerList.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerList.java deleted file mode 100644 index 072da17153..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerList.java +++ /dev/null @@ -1,202 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.delegate.IContainerList; - -import java.util.Collection; -import java.util.List; -import java.util.ListIterator; - -/** - * @author Eike Stepper - */ -public class ContainerList<E> extends ContainerCollection<E> implements IContainerList<E> -{ - public ContainerList(List<E> delegate) - { - super(delegate); - } - - @Override - public List<E> getDelegate() - { - return (List<E>)super.getDelegate(); - } - - /** - * @category WRITE - */ - public void add(int index, E element) - { - getDelegate().add(index, element); - fireAddedEvent(element); - } - - /** - * @category WRITE - */ - public boolean addAll(int index, Collection<? extends E> c) - { - ContainerEvent<E> event = createEvent(getDelegate(), IContainerDelta.Kind.ADDED); - getDelegate().addAll(index, c); - return dispatchEvent(event); - } - - /** - * @category READ - */ - public E get(int index) - { - return getDelegate().get(index); - } - - /** - * @category READ - */ - public int indexOf(Object o) - { - return getDelegate().indexOf(o); - } - - /** - * @category READ - */ - public int lastIndexOf(Object o) - { - return getDelegate().lastIndexOf(o); - } - - /** - * @category READ - */ - public ListIterator<E> listIterator() - { - return new DelegatingListIterator(getDelegate().listIterator()); - } - - /** - * @category READ - */ - public ListIterator<E> listIterator(int index) - { - return new DelegatingListIterator(getDelegate().listIterator(index)); - } - - /** - * @category WRITE - */ - public E remove(int index) - { - E removed = getDelegate().remove(index); - if (removed != null) - { - fireRemovedEvent(removed); - } - - return removed; - } - - /** - * @category WRITE - */ - public E set(int index, E element) - { - E removed = getDelegate().set(index, element); - ContainerEvent<E> event = new ContainerEvent<E>(ContainerList.this); - event.addDelta(removed, IContainerDelta.Kind.REMOVED); - event.addDelta(element, IContainerDelta.Kind.ADDED); - fireEvent(event); - return removed; - } - - /** - * @category READ - */ - public List<E> subList(int fromIndex, int toIndex) - { - return getDelegate().subList(fromIndex, toIndex); - } - - /** - * @author Eike Stepper - */ - public class DelegatingListIterator extends DelegatingIterator implements ListIterator<E> - { - public DelegatingListIterator(ListIterator<E> delegate) - { - super(delegate); - } - - @Override - public ListIterator<E> getDelegate() - { - return (ListIterator<E>)super.getDelegate(); - } - - /** - * @category WRITE - */ - public void add(E o) - { - getDelegate().add(o); - fireAddedEvent(o); - last = o; - } - - /** - * @category WRITE - */ - public void set(E o) - { - getDelegate().set(o); - ContainerEvent<E> event = new ContainerEvent<E>(ContainerList.this); - event.addDelta(last, IContainerDelta.Kind.REMOVED); - event.addDelta(o, IContainerDelta.Kind.ADDED); - fireEvent(event); - last = o; - } - - /** - * @category READ - */ - public boolean hasPrevious() - { - return getDelegate().hasPrevious(); - } - - /** - * @category READ - */ - public int nextIndex() - { - return getDelegate().nextIndex(); - } - - /** - * @category READ - */ - public E previous() - { - return getDelegate().previous(); - } - - /** - * @category READ - */ - public int previousIndex() - { - return getDelegate().previousIndex(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerMap.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerMap.java deleted file mode 100644 index ea033de411..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerMap.java +++ /dev/null @@ -1,197 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.util.collection.MapEntry; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.container.delegate.IContainerMap; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * @author Eike Stepper - */ -public class ContainerMap<K, V> extends AbstractDelegator<Map.Entry<K, V>> implements IContainerMap<K, V> -{ - private Map<K, V> delegate; - - public ContainerMap(Map<K, V> delegate) - { - this.delegate = delegate; - } - - public Map<K, V> getDelegate() - { - return delegate; - } - - /** - * @category WRITE - */ - public void clear() - { - if (!isEmpty()) - { - ContainerEvent<Map.Entry<K, V>> event = createEvent(getDelegate().entrySet(), IContainerDelta.Kind.REMOVED); - getDelegate().clear(); - fireEvent(event); - } - } - - /** - * @category WRITE - */ - public V put(K key, V value) - { - ContainerEvent<Map.Entry<K, V>> event = new ContainerEvent<Map.Entry<K, V>>(this); - V removed = getDelegate().put(key, value); - if (removed != null) - { - event.addDelta(new ContainerMapEntry<K, V>(key, removed), IContainerDelta.Kind.REMOVED); - } - - event.addDelta(new ContainerMapEntry<K, V>(key, value), IContainerDelta.Kind.ADDED); - fireEvent(event); - return removed; - } - - /** - * @category WRITE - */ - public void putAll(Map<? extends K, ? extends V> t) - { - ContainerEvent<Map.Entry<K, V>> event = new ContainerEvent<Map.Entry<K, V>>(this); - Iterator<? extends Entry<? extends K, ? extends V>> i = t.entrySet().iterator(); - while (i.hasNext()) - { - Entry<? extends K, ? extends V> entry = i.next(); - K key = entry.getKey(); - V value = entry.getValue(); - V removed = getDelegate().put(key, value); - if (removed != null) - { - event.addDelta(new ContainerMapEntry<K, V>(key, removed), IContainerDelta.Kind.REMOVED); - } - - event.addDelta(new ContainerMapEntry<K, V>(key, value), IContainerDelta.Kind.ADDED); - } - - dispatchEvent(event); - } - - /** - * @category WRITE - */ - public V remove(Object key) - { - V removed = getDelegate().remove(key); - if (removed != null) - { - fireRemovedEvent(new ContainerMapEntry<Object, V>(key, removed)); - } - - return removed; - } - - /** - * @category READ - */ - public boolean containsKey(Object key) - { - return getDelegate().containsKey(key); - } - - /** - * @category READ - */ - public boolean containsValue(Object value) - { - return getDelegate().containsValue(value); - } - - /** - * @category READ - */ - public V get(Object key) - { - return getDelegate().get(key); - } - - /** - * @category READ - */ - public int size() - { - return getDelegate().size(); - } - - /** - * @category READ - */ - @SuppressWarnings("unchecked") - public Map.Entry<K, V>[] getElements() - { - return (Entry<K, V>[])getDelegate().entrySet().toArray(); - } - - /** - * @category READ - */ - public boolean isEmpty() - { - return getDelegate().isEmpty(); - } - - /** - * @category READ - */ - public Set<Map.Entry<K, V>> entrySet() - { - return new ContainerSet<Map.Entry<K, V>>(getDelegate().entrySet()); - } - - /** - * @category READ - */ - public Set<K> keySet() - { - return new ContainerSet<K>(getDelegate().keySet()); - } - - /** - * @category READ - */ - public Collection<V> values() - { - return new ContainerCollection<V>(getDelegate().values()); - } - - /** - * @author Eike Stepper - */ - private static final class ContainerMapEntry<K, V> extends MapEntry<K, V> - { - public ContainerMapEntry(K key, V value) - { - super(key, value); - } - - @Override - public V setValue(V value) - { - throw new UnsupportedOperationException(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerQueue.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerQueue.java deleted file mode 100644 index bb9568afc1..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerQueue.java +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.util.container.delegate.IContainerQueue; - -import java.util.Queue; - -/** - * @author Eike Stepper - */ -public class ContainerQueue<E> extends ContainerCollection<E> implements IContainerQueue<E> -{ - public ContainerQueue(Queue<E> delegate) - { - super(delegate); - } - - @Override - public Queue<E> getDelegate() - { - return (Queue<E>)super.getDelegate(); - } - - /** - * @category READ - */ - public E element() - { - return getDelegate().element(); - } - - /** - * @category WRITE - */ - public boolean offer(E o) - { - boolean modified = getDelegate().offer(o); - if (modified) - { - fireAddedEvent(o); - } - - return modified; - } - - /** - * @category READ - */ - public E peek() - { - return getDelegate().element(); - } - - /** - * @category WRITE - */ - public E poll() - { - E removed = getDelegate().poll(); - if (removed != null) - { - fireRemovedEvent(removed); - } - - return removed; - } - - /** - * @category WRITE - */ - public E remove() - { - E removed = getDelegate().remove(); - if (removed != null) - { - fireRemovedEvent(removed); - } - - return removed; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSet.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSet.java deleted file mode 100644 index 309ee30586..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSet.java +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.util.container.delegate.IContainerSet; - -import java.util.Set; - -/** - * @author Eike Stepper - */ -public class ContainerSet<E> extends ContainerCollection<E> implements IContainerSet<E> -{ - public ContainerSet(Set<E> delegate) - { - super(delegate); - } - - @Override - public Set<E> getDelegate() - { - return (Set<E>)super.getDelegate(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSortedSet.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSortedSet.java deleted file mode 100644 index 1e00c6c7dd..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/container/delegate/ContainerSortedSet.java +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.container.delegate; - -import org.eclipse.net4j.util.container.delegate.IContainerSortedSet; - -import java.util.Comparator; -import java.util.SortedSet; - -/** - * @author Eike Stepper - */ -public class ContainerSortedSet<E> extends ContainerSet<E> implements IContainerSortedSet<E> -{ - public ContainerSortedSet(SortedSet<E> delegate) - { - super(delegate); - } - - @Override - public SortedSet<E> getDelegate() - { - return (SortedSet<E>)super.getDelegate(); - } - - /** - * @category READ - */ - public Comparator<? super E> comparator() - { - return getDelegate().comparator(); - } - - /** - * @category READ - */ - public E first() - { - return getDelegate().first(); - } - - /** - * @category READ - */ - public E last() - { - return getDelegate().last(); - } - - /** - * @category READ - */ - public SortedSet<E> headSet(E toElement) - { - return getDelegate().headSet(toElement); - } - - /** - * @category READ - */ - public SortedSet<E> subSet(E fromElement, E toElement) - { - return getDelegate().subSet(fromElement, toElement); - } - - /** - * @category READ - */ - public SortedSet<E> tailSet(E fromElement) - { - return getDelegate().tailSet(fromElement); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Event.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Event.java deleted file mode 100644 index 9e70cbbdef..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Event.java +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.event; - -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.INotifier; - -import java.util.EventObject; - -/** - * @author Eike Stepper - */ -public class Event extends EventObject implements IEvent -{ - private static final long serialVersionUID = 1L; - - public Event(INotifier notifier) - { - super(notifier); - } - - public INotifier getSource() - { - return (INotifier)source; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java deleted file mode 100644 index c7df10f312..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.event; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.event.INotifier; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class Notifier implements INotifier.Introspection -{ - /** - * TODO Optimize by storing an array - */ - private List<IListener> listeners = new ArrayList<IListener>(0); - - public Notifier() - { - } - - public void addListener(IListener listener) - { - synchronized (listeners) - { - listeners.add(listener); - } - } - - public void removeListener(IListener listener) - { - synchronized (listeners) - { - listeners.remove(listener); - } - } - - public boolean hasListeners() - { - return !listeners.isEmpty(); - } - - public IListener[] getListeners() - { - synchronized (listeners) - { - return listeners.toArray(new IListener[listeners.size()]); - } - } - - public void fireEvent(IEvent event) - { - for (IListener listener : getListeners()) - { - try - { - listener.notifyEvent(event); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/Factory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/Factory.java deleted file mode 100644 index a64ed8747a..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/Factory.java +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.factory; - -import org.eclipse.net4j.util.factory.IFactory; - -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public abstract class Factory implements IFactory -{ - private FactoryKey key; - - public Factory(FactoryKey key) - { - this.key = key; - } - - public Factory(String productGroup, String type) - { - this(new FactoryKey(productGroup, type)); - } - - public FactoryKey getKey() - { - return key; - } - - public String getProductGroup() - { - return key.getProductGroup(); - } - - public String getType() - { - return key.getType(); - } - - public String getDescriptionFor(Object product) - { - return null; - } - - @Override - public String toString() - { - return MessageFormat.format("Factory[{0}, {1}]", getProductGroup(), getType()); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryCreationException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryCreationException.java deleted file mode 100644 index 56369be7c4..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryCreationException.java +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.factory; - -/** - * @author Eike Stepper - */ -public class FactoryCreationException extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - public FactoryCreationException() - { - } - - public FactoryCreationException(String message) - { - super(message); - } - - public FactoryCreationException(Throwable cause) - { - super(cause); - } - - public FactoryCreationException(String message, Throwable cause) - { - super(message, cause); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryDescriptor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryDescriptor.java deleted file mode 100644 index 0e5d2e19c7..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryDescriptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.factory; - -import org.eclipse.net4j.util.factory.IFactory; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; - -/** - * @author Eike Stepper - */ -public class FactoryDescriptor extends Factory -{ - private static final String ATTR_PRODUCT_GROUP = "productGroup"; - - private static final String ATTR_TYPE = "type"; - - private static final String ATTR_CLASS = "class"; - - private IConfigurationElement configurationElement; - - public FactoryDescriptor(IConfigurationElement configurationElement) - { - super(createFactoryKey(configurationElement)); - this.configurationElement = configurationElement; - } - - public IConfigurationElement getConfigurationElement() - { - return configurationElement; - } - - public IFactory createFactory() - { - try - { - return (IFactory)configurationElement.createExecutableExtension(ATTR_CLASS); - } - catch (CoreException ex) - { - throw new FactoryCreationException(ex); - } - } - - public Object create(String description) - { - throw new UnsupportedOperationException(); - } - - @Override - public String getDescriptionFor(Object product) - { - throw new UnsupportedOperationException(); - } - - private static FactoryKey createFactoryKey(IConfigurationElement element) - { - String productGroup = element.getAttribute(ATTR_PRODUCT_GROUP); - String type = element.getAttribute(ATTR_TYPE); - return new FactoryKey(productGroup, type); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryKey.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryKey.java deleted file mode 100644 index b6d9bc83f9..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/FactoryKey.java +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.factory; - -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.StringUtil; -import org.eclipse.net4j.util.factory.IFactoryKey; - -import java.io.Serializable; -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public final class FactoryKey implements IFactoryKey, Serializable, Comparable<FactoryKey> -{ - private static final long serialVersionUID = 1L; - - private String productGroup; - - private String type; - - public FactoryKey(String productGroup, String type) - { - this.productGroup = productGroup; - this.type = type; - } - - public String getProductGroup() - { - return productGroup; - } - - public void setProductGroup(String productGroup) - { - this.productGroup = productGroup; - } - - public String getType() - { - return type; - } - - public void setType(String type) - { - this.type = type; - } - - @Override - public boolean equals(Object obj) - { - if (obj == this) - { - return true; - } - - if (obj instanceof FactoryKey) - { - FactoryKey key = (FactoryKey)obj; - return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(type, key.type); - } - - return false; - } - - @Override - public int hashCode() - { - return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(type); - } - - @Override - public String toString() - { - return MessageFormat.format("{0}[{1}]", productGroup, type); - } - - public int compareTo(FactoryKey key) - { - int result = StringUtil.compare(productGroup, key.productGroup); - if (result == 0) - { - result = StringUtil.compare(type, key.type); - } - - return result; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java index bb3fd0ab4f..1af448121b 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/factory/PluginFactoryRegistry.java @@ -11,9 +11,10 @@ package org.eclipse.net4j.internal.util.factory; import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.registry.HashMapRegistry; +import org.eclipse.net4j.util.factory.FactoryDescriptor; import org.eclipse.net4j.util.factory.IFactory; import org.eclipse.net4j.util.factory.IFactoryKey; +import org.eclipse.net4j.util.registry.HashMapRegistry; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionDelta; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java deleted file mode 100644 index 50e68f3997..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java +++ /dev/null @@ -1,228 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.lifecycle; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.event.Notifier; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.util.CheckUtil; -import org.eclipse.net4j.util.ReflectUtil; -import org.eclipse.net4j.util.lifecycle.ILifecycle; -import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; -import org.eclipse.net4j.util.lifecycle.ILifecycleState; -import org.eclipse.net4j.util.lifecycle.LifecycleException; - -/** - * @author Eike Stepper - */ -public class Lifecycle extends Notifier implements ILifecycle.Introspection -{ - public static boolean USE_LABEL = true; - - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_LIFECYCLE, Lifecycle.class); - - private static final ContextTracer DUMPER = new ContextTracer(OM.DEBUG_LIFECYCLE_DUMP, Lifecycle.class); - - private static final boolean TRACE_IGNORING = false; - - private ILifecycleState lifecycleState = ILifecycleState.INACTIVE; - - protected Lifecycle() - { - } - - public final void activate() throws LifecycleException - { - if (lifecycleState == ILifecycleState.INACTIVE) - { - if (TRACER.isEnabled()) - { - TRACER.trace("Activating " + this);//$NON-NLS-1$ - } - - lifecycleState = ILifecycleState.ACTIVATING; - fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ABOUT_TO_ACTIVATE)); - - try - { - doBeforeActivate(); - doActivate(); - } - catch (RuntimeException ex) - { - throw ex; - } - catch (Exception ex) - { - throw new LifecycleException(ex); - } - - if (!isDeferredActivation()) - { - deferredActivate(); - } - } - else - { - if (TRACE_IGNORING && TRACER.isEnabled()) - { - TRACER.format("Ignoring activation in state {0} for {1}", lifecycleState, this);//$NON-NLS-1$ - } - } - } - - public final Exception deactivate() - { - if (lifecycleState == ILifecycleState.ACTIVE || lifecycleState == ILifecycleState.ACTIVATING) - { - if (TRACER.isEnabled()) - { - TRACER.trace("Deactivating " + this);//$NON-NLS-1$ - } - - try - { - lifecycleState = ILifecycleState.DEACTIVATING; - doBeforeDeactivate(); - fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ABOUT_TO_DEACTIVATE)); - - if (!isDeferredDeactivation()) - { - deferredDeactivate(); - } - } - catch (Exception ex) - { - OM.LOG.error(ex); - return ex; - } - } - else - { - if (TRACE_IGNORING && TRACER.isEnabled()) - { - TRACER.format("Ignoring deactivation in state {0} for {1}", lifecycleState, this);//$NON-NLS-1$ - } - } - - return null; - } - - public final ILifecycleState getLifecycleState() - { - return lifecycleState; - } - - public final boolean isActive() - { - return lifecycleState == ILifecycleState.ACTIVE; - } - - @Override - public String toString() - { - if (USE_LABEL) - { - return ReflectUtil.getLabel(this); - } - - return super.toString(); - } - - protected final void dump() - { - if (DUMPER.isEnabled()) - { - DUMPER.trace("DUMP" + ReflectUtil.toString(this)); //$NON-NLS-1$ - } - } - - protected final void checkActive() - { - if (lifecycleState != ILifecycleState.ACTIVE) - { - throw new IllegalStateException("Not active: " + this); - } - } - - protected final void checkInactive() - { - if (lifecycleState != ILifecycleState.INACTIVE) - { - throw new IllegalStateException("Not inactive: " + this); - } - } - - protected final void checkNull(Object handle, String msg) throws NullPointerException - { - CheckUtil.checkNull(handle, msg); - } - - protected final void checkArg(boolean expr, String msg) throws IllegalArgumentException - { - CheckUtil.checkArg(expr, msg); - } - - protected final void checkArg(Object handle, String handleName) throws IllegalArgumentException - { - CheckUtil.checkState(handle, handleName); - } - - protected final void checkState(boolean expr, String msg) throws IllegalStateException - { - CheckUtil.checkState(expr, msg); - } - - protected final void checkState(Object handle, String handleName) throws IllegalStateException - { - CheckUtil.checkState(handle, handleName); - } - - protected final void deferredActivate() - { - lifecycleState = ILifecycleState.ACTIVE; - fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ACTIVATED)); - dump(); - } - - protected final void deferredDeactivate() throws Exception - { - doDeactivate(); - lifecycleState = ILifecycleState.INACTIVE; - fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.DEACTIVATED)); - } - - protected boolean isDeferredActivation() - { - return false; - } - - protected boolean isDeferredDeactivation() - { - return false; - } - - protected void doBeforeActivate() throws Exception - { - } - - protected void doActivate() throws Exception - { - } - - protected void doBeforeDeactivate() throws Exception - { - } - - protected void doDeactivate() throws Exception - { - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEvent.java deleted file mode 100644 index 98083141f6..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.lifecycle; - -import org.eclipse.net4j.internal.util.event.Event; -import org.eclipse.net4j.util.lifecycle.ILifecycle; -import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; - -/** - * @author Eike Stepper - */ -public class LifecycleEvent extends Event implements ILifecycleEvent -{ - private static final long serialVersionUID = 1L; - - private Kind kind; - - public LifecycleEvent(Lifecycle lifecycle, Kind kind) - { - super(lifecycle); - this.kind = kind; - } - - public ILifecycle getLifecycle() - { - return (ILifecycle)getSource(); - } - - public Kind getKind() - { - return kind; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEventAdapter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEventAdapter.java deleted file mode 100644 index 05e8bd6a45..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/LifecycleEventAdapter.java +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.lifecycle; - -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.lifecycle.ILifecycle; -import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; - -/** - * @author Eike Stepper - */ -public class LifecycleEventAdapter implements IListener -{ - public LifecycleEventAdapter() - { - } - - public final void notifyEvent(IEvent event) - { - if (event instanceof ILifecycleEvent) - { - ILifecycleEvent e = (ILifecycleEvent)event; - notifyLifecycleEvent(e); - } - else - { - notifyOtherEvent(event); - } - } - - protected void notifyLifecycleEvent(ILifecycleEvent event) - { - switch (event.getKind()) - { - case ABOUT_TO_ACTIVATE: - onAboutToActivate(event.getLifecycle()); - break; - case ACTIVATED: - onActivated(event.getLifecycle()); - break; - case ABOUT_TO_DEACTIVATE: - onAboutToDeactivate(event.getLifecycle()); - break; - case DEACTIVATED: - onDeactivated(event.getLifecycle()); - break; - } - } - - protected void notifyOtherEvent(IEvent event) - { - } - - protected void onAboutToActivate(ILifecycle lifecycle) - { - } - - protected void onActivated(ILifecycle lifecycle) - { - } - - protected void onAboutToDeactivate(ILifecycle lifecycle) - { - } - - protected void onDeactivated(ILifecycle lifecycle) - { - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/QueueWorker.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/QueueWorker.java deleted file mode 100644 index 6aea5c6bf4..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/QueueWorker.java +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.lifecycle; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * @author Eike Stepper - */ -public abstract class QueueWorker<E> extends Worker -{ - private BlockingQueue<E> queue; - - private long pollMillis; - - public QueueWorker() - { - setPollMillis(100); - } - - public long getPollMillis() - { - return pollMillis; - } - - public void setPollMillis(long pollMillis) - { - this.pollMillis = pollMillis; - } - - public boolean addWork(E element) - { - if (queue != null) - { - return queue.offer(element); - } - - return false; - } - - @Override - protected final void work(WorkContext context) throws Exception - { - E element = queue.poll(pollMillis, TimeUnit.MILLISECONDS); - if (element != null) - { - work(context, element); - } - } - - protected abstract void work(WorkContext context, E element); - - protected BlockingQueue<E> createQueue() - { - return new LinkedBlockingQueue<E>(); - } - - @Override - protected void doActivate() throws Exception - { - queue = createQueue(); - super.doActivate(); - } - - @Override - protected void doDeactivate() throws Exception - { - super.doDeactivate(); - if (queue != null) - { - queue.clear(); - queue = null; - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java deleted file mode 100644 index be6d38efd8..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java +++ /dev/null @@ -1,250 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.lifecycle; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.util.concurrent.ConcurrencyUtil; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * @author Eike Stepper - */ -public abstract class Worker extends Lifecycle -{ - public static final int DEFAULT_TIMEOUT = 2000; - - private boolean daemon; - - private long activationTimeout = DEFAULT_TIMEOUT; - - private long deactivationTimeout = DEFAULT_TIMEOUT; - - private transient CountDownLatch activationLatch; - - private transient WorkerThread workerThread; - - public Worker() - { - } - - public boolean isDaemon() - { - return daemon; - } - - public void setDaemon(boolean daemon) - { - this.daemon = daemon; - } - - public long getActivationTimeout() - { - return activationTimeout; - } - - public void setActivationTimeout(long activationTimeout) - { - this.activationTimeout = activationTimeout; - } - - public long getDeactivationTimeout() - { - return deactivationTimeout; - } - - public void setDeactivationTimeout(long deactivationTimeout) - { - this.deactivationTimeout = deactivationTimeout; - } - - @Override - protected void doActivate() throws Exception - { - super.doActivate(); - activationLatch = new CountDownLatch(1); - String threadName = getThreadName(); - workerThread = threadName == null ? new WorkerThread() : new WorkerThread(threadName); - workerThread.start(); - if (!activationLatch.await(activationTimeout, TimeUnit.MILLISECONDS)) - { - try - { - workerThread.stopRunning(); - workerThread.interrupt(); - } - catch (RuntimeException ignore) - { - } - - throw new TimeoutException("Worker thread activation timed out after " + activationTimeout + " millis"); - } - } - - @Override - protected void doDeactivate() throws Exception - { - try - { - workerThread.stopRunning(); - workerThread.interrupt(); - workerThread.join(deactivationTimeout); - } - catch (RuntimeException ignore) - { - } - - super.doDeactivate(); - } - - protected String getThreadName() - { - return null; - } - - protected abstract void work(WorkContext context) throws Exception; - - /** - * @author Eike Stepper - */ - private final class WorkerThread extends Thread - { - private boolean running = true; - - public WorkerThread() - { - setDaemon(daemon); - } - - public WorkerThread(String threadName) - { - super(threadName); - setDaemon(daemon); - } - - public void stopRunning() - { - running = false; - } - - @Override - public void run() - { - WorkContext context = new WorkContext(); - activationLatch.countDown(); - while (running && !isInterrupted()) - { - try - { - context.increaseCount(); - work(context); - } - catch (NextWork nextWork) - { - nextWork.pause(); - } - catch (Terminate terminate) - { - break; - } - catch (InterruptedException ex) - { - break; - } - catch (Exception ex) - { - OM.LOG.error(ex); - break; - } - } - - deactivate(); - } - } - - /** - * @author Eike Stepper - */ - public final class WorkContext - { - private long count; - - public WorkContext() - { - } - - public long getCount() - { - return count; - } - - public void nextWork() - { - throw new NextWork(); - } - - public void nextWork(long pauseMillis) - { - throw new NextWork(pauseMillis); - } - - public void terminate() - { - throw new Terminate(); - } - - private void increaseCount() - { - ++count; - } - } - - /** - * @author Eike Stepper - */ - private static final class NextWork extends RuntimeException - { - private static final long serialVersionUID = 1L; - - private long pauseMillis; - - public NextWork() - { - } - - public NextWork(long pauseMillis) - { - this.pauseMillis = pauseMillis; - } - - public void pause() - { - if (pauseMillis > 0) - { - ConcurrencyUtil.sleep(pauseMillis); - } - } - } - - /** - * @author Eike Stepper - */ - private static final class Terminate extends RuntimeException - { - private static final long serialVersionUID = 1L; - - public Terminate() - { - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java index 5c5a6a06fb..ac210bbf9a 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/LegacyBundle.java @@ -104,19 +104,23 @@ public class LegacyBundle extends AbstractBundle // the plugin.properties. // // For a plugin.xml with runtime="common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/CommonPlugin.class + // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/ + // CommonPlugin.class // // For a plugin.xml with runtime="runtime/common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common/CommonPlugin.class + //jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common + // /CommonPlugin.class // // For a plugin.xml with runtime="." where the plugin is jarred: - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.class + //jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin. + // class // // For a plugin.xml with runtime="." where the plugin is not jarred. - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class + //file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class // // Running in PDE with bin on classpath: - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.class + // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin. + // class String className = accessor.getName(); URL url = accessor.getResource(ReflectUtil.getSimpleName(accessor) + ".class"); //$NON-NLS-1$ diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/EclipseLoggingBridge.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/EclipseLoggingBridge.java deleted file mode 100644 index e9b36517a3..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/EclipseLoggingBridge.java +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.log; - -import org.eclipse.net4j.internal.util.om.OSGiBundle; -import org.eclipse.net4j.util.om.log.OMLogHandler; -import org.eclipse.net4j.util.om.log.OMLogger; -import org.eclipse.net4j.util.om.log.OMLogger.Level; - -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -/** - * @author Eike Stepper - */ -public class EclipseLoggingBridge implements OMLogHandler -{ - /** - * @Singleton - */ - public static final EclipseLoggingBridge INSTANCE = new EclipseLoggingBridge(); - - protected EclipseLoggingBridge() - { - } - - public void logged(OMLogger logger, Level level, String msg, Throwable t) - { - try - { - OSGiBundle bundle = (OSGiBundle)logger.getBundle(); - ILog log = Platform.getLog(bundle.getBundleContext().getBundle()); - log.log(new Status(toEclipse(level), bundle.getBundleID(), IStatus.OK, msg, t)); - } - catch (RuntimeException ignore) - { - } - } - - public static int toEclipse(Level level) - { - switch (level) - { - case ERROR: - return IStatus.ERROR; - case WARN: - return IStatus.WARNING; - case INFO: - return IStatus.INFO; - case DEBUG: - return IStatus.OK; - default: - throw new IllegalArgumentException("Illegal log level: " + level); //$NON-NLS-1$ - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/Logger.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/Logger.java deleted file mode 100644 index 72737ceebb..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/Logger.java +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.log; - -import org.eclipse.net4j.internal.util.bundle.AbstractPlatform; -import org.eclipse.net4j.util.om.OMBundle; -import org.eclipse.net4j.util.om.log.OMLogger; - -/** - * @author Eike Stepper - */ -public class Logger implements OMLogger -{ - private OMBundle bundle; - - public Logger(OMBundle bundle) - { - this.bundle = bundle; - } - - public OMBundle getBundle() - { - return bundle; - } - - public void log(Level level, String msg, Throwable t) - { - ((AbstractPlatform)bundle.getPlatform()).log(this, level, msg, t); - } - - public void error(String msg, Throwable t) - { - log(Level.ERROR, msg, t); - } - - public void warn(String msg, Throwable t) - { - log(Level.WARN, msg, t); - } - - public void info(String msg, Throwable t) - { - log(Level.INFO, msg, t); - } - - public void debug(String msg, Throwable t) - { - log(Level.DEBUG, msg, t); - } - - public void log(Level level, String msg) - { - log(level, msg, null); - } - - public void error(String msg) - { - log(Level.ERROR, msg); - } - - public void warn(String msg) - { - log(Level.WARN, msg); - } - - public void info(String msg) - { - log(Level.INFO, msg); - } - - public void debug(String msg) - { - log(Level.DEBUG, msg); - } - - public void log(Level level, Throwable t) - { - String msg = t.getMessage(); - if (msg == null) - { - msg = t.getClass().getSimpleName(); - } - - log(level, msg, t); - } - - public void error(Throwable t) - { - log(Level.ERROR, t); - } - - public void warn(Throwable t) - { - log(Level.WARN, t); - } - - public void info(Throwable t) - { - log(Level.INFO, t); - } - - public void debug(Throwable t) - { - log(Level.DEBUG, t); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/OSGiLoggingBridge.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/OSGiLoggingBridge.java deleted file mode 100644 index e84a649328..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/OSGiLoggingBridge.java +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.log; - -import org.eclipse.net4j.internal.util.om.OSGiBundle; -import org.eclipse.net4j.util.om.log.OMLogHandler; -import org.eclipse.net4j.util.om.log.OMLogger; -import org.eclipse.net4j.util.om.log.OMLogger.Level; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; - -/** - * @author Eike Stepper - */ -public class OSGiLoggingBridge implements OMLogHandler -{ - // @Singleton - public static final OSGiLoggingBridge INSTANCE = new OSGiLoggingBridge(); - - protected OSGiLoggingBridge() - { - } - - public void logged(OMLogger logger, Level level, String msg, Throwable t) - { - try - { - BundleContext bundleContext = ((OSGiBundle)logger.getBundle()).getBundleContext(); - logged(bundleContext, level, msg, t); - } - catch (RuntimeException ignore) - { - } - } - - public void logged(BundleContext bundleContext, Level level, String msg, Throwable t) - { - LogService logService = getLogService(bundleContext); - logService.log(toOSGi(level), msg, t); - } - - protected LogService getLogService(BundleContext bundleContext) - { - try - { - ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName()); - LogService logService = (LogService)bundleContext.getService(ref); - return logService; - } - catch (RuntimeException ex) - { - throw new IllegalStateException("Log service not found", ex); //$NON-NLS-1$ - } - } - - public static int toOSGi(Level level) - { - switch (level) - { - case ERROR: - return LogService.LOG_ERROR; - case WARN: - return LogService.LOG_WARNING; - case INFO: - return LogService.LOG_INFO; - case DEBUG: - return LogService.LOG_DEBUG; - default: - throw new IllegalArgumentException("Illegal log level: " + level); //$NON-NLS-1$ - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/PrintLogHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/PrintLogHandler.java deleted file mode 100644 index 753494a628..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/log/PrintLogHandler.java +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.log; - -import org.eclipse.net4j.util.io.IOUtil; -import org.eclipse.net4j.util.om.log.OMLogHandler; -import org.eclipse.net4j.util.om.log.OMLogger; -import org.eclipse.net4j.util.om.log.OMLogger.Level; - -import java.io.PrintStream; - -/** - * @author Eike Stepper - */ -public class PrintLogHandler implements OMLogHandler -{ - public static final PrintLogHandler CONSOLE = new PrintLogHandler(); - - private PrintStream out; - - private PrintStream err; - - public PrintLogHandler(PrintStream out, PrintStream err) - { - this.out = out; - this.err = err; - } - - protected PrintLogHandler() - { - this(IOUtil.OUT(), IOUtil.ERR()); - } - - public void logged(OMLogger logger, Level level, String msg, Throwable t) - { - try - { - PrintStream stream = level == Level.ERROR ? err : out; - stream.println(toString(level) + " " + msg); //$NON-NLS-1$ - if (t != null) - { - IOUtil.print(t, stream); - } - } - catch (RuntimeException ignore) - { - } - } - - public static String toString(Level level) - { - switch (level) - { - case ERROR: - return "[ERROR]"; //$NON-NLS-1$ - case WARN: - return "[WARN]"; //$NON-NLS-1$ - case INFO: - return "[INFO]"; //$NON-NLS-1$ - case DEBUG: - return "[DEBUG]"; //$NON-NLS-1$ - default: - throw new IllegalArgumentException("Illegal log level: " + level); //$NON-NLS-1$ - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java index f83d3d0564..7aae179ea4 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java @@ -11,12 +11,12 @@ package org.eclipse.net4j.internal.util.om.monitor; import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; import org.eclipse.net4j.util.om.monitor.MonitorCanceledException; import org.eclipse.net4j.util.om.monitor.MonitorNotBegunException; import org.eclipse.net4j.util.om.monitor.OMMonitor; import org.eclipse.net4j.util.om.monitor.OMSubMonitor; import org.eclipse.net4j.util.om.monitor.TotalWorkExceededException; +import org.eclipse.net4j.util.om.trace.ContextTracer; /** * @author Eike Stepper diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java index ab8910c4e7..cc287aac58 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/Preferences.java @@ -11,7 +11,7 @@ package org.eclipse.net4j.internal.util.om.pref; import org.eclipse.net4j.internal.util.bundle.AbstractBundle; -import org.eclipse.net4j.internal.util.event.Notifier; +import org.eclipse.net4j.util.event.Notifier; import org.eclipse.net4j.util.io.IORunnable; import org.eclipse.net4j.util.io.IORuntimeException; import org.eclipse.net4j.util.io.IOUtil; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java index d2ae7da465..6bde8acad3 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/pref/PreferencesChangeEvent.java @@ -10,7 +10,7 @@ **************************************************************************/ package org.eclipse.net4j.internal.util.om.pref; -import org.eclipse.net4j.internal.util.event.Event; +import org.eclipse.net4j.util.event.Event; import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent; /** diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/ContextTracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/ContextTracer.java deleted file mode 100644 index 838ccb63a7..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/ContextTracer.java +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.util.om.OMBundle; -import org.eclipse.net4j.util.om.trace.OMTracer; - -/** - * @author Eike Stepper - */ -public class ContextTracer -{ - private OMTracer delegate; - - private Class<?> context; - - public ContextTracer(OMTracer delegate, Class<?> context) - { - this.delegate = delegate; - this.context = context; - } - - public OMBundle getBundle() - { - return delegate.getBundle(); - } - - public String getFullName() - { - return delegate.getFullName(); - } - - public String getName() - { - return delegate.getName(); - } - - public OMTracer getDelegate() - { - return delegate; - } - - public OMTracer getParent() - { - return delegate.getParent(); - } - - public boolean isEnabled() - { - return delegate.isEnabled(); - } - - public void setEnabled(boolean enabled) - { - delegate.setEnabled(enabled); - } - - public void format(String pattern, Object... args) - { - delegate.format(context, pattern, args); - } - - public void format(String pattern, Throwable t, Object... args) - { - delegate.format(context, pattern, t, args); - } - - public void trace(String msg, Throwable t) - { - delegate.trace(context, msg, t); - } - - public void trace(String msg) - { - delegate.trace(context, msg); - } - - public void trace(Throwable t) - { - delegate.trace(context, t); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java deleted file mode 100644 index 2fd536bb74..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PerfTracer.java +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.util.om.trace.OMTracer; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * @author Eike Stepper - */ -public class PerfTracer extends ContextTracer -{ - public static final long NOT_STARTED = 0L; - - private ConcurrentMap<Object, Long> timers = new ConcurrentHashMap<Object, Long>(); - - public PerfTracer(OMTracer delegate, Class<?> context) - { - super(delegate, context); - } - - public void start(Object object) - { - if (isEnabled()) - { - timers.put(object, System.currentTimeMillis()); - } - } - - public long stop(Object object) - { - long duration = NOT_STARTED; - if (isEnabled()) - { - Long timer = timers.remove(object); - if (timer != null) - { - duration = System.currentTimeMillis() - timer; - format("{0} = {1} millis", object, duration); - } - } - - return duration; - } - - public long getDuration(Object object) - { - long duration = NOT_STARTED; - if (isEnabled()) - { - Long timer = timers.get(object); - if (timer != null) - { - duration = System.currentTimeMillis() - timer; - } - } - - return duration; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PrintTraceHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PrintTraceHandler.java deleted file mode 100644 index 0696770351..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/PrintTraceHandler.java +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.util.io.IOUtil; -import org.eclipse.net4j.util.om.trace.OMTraceHandler; -import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent; -import org.eclipse.net4j.util.om.trace.OMTracer; - -import java.io.PrintStream; -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public class PrintTraceHandler implements OMTraceHandler -{ - public static final PrintTraceHandler CONSOLE = new PrintTraceHandler(); - - private PrintStream stream; - - private String pattern; - - private boolean shortContext; - - public PrintTraceHandler(PrintStream stream) - { - this.stream = stream; - } - - protected PrintTraceHandler() - { - this(IOUtil.OUT()); - } - - public String getPattern() - { - return pattern; - } - - /** - * Pattern arguments: - * <p> - * <ul> - * <li>{0} --> String <b>tracerName</b><br> - * <li>{1} --> String <b>tracerShort</b><br> - * <li>{2} --> String <b>contextName</b><br> - * <li>{3} --> String <b>contextShort</b><br> - * <li>{4} --> long <b>timeStamp</b><br> - * <li>{5} --> String <b>message</b><br> - * <li>{6} --> String <b>threadName</b><br> - * <li>{7} --> long <b>threadID</b><br> - * <li>{8} --> int <b>threadPriority</b><br> - * <li>{9} --> Thread.State <b>threadState</b><br> - * </ul> - */ - public void setPattern(String pattern) - { - this.pattern = pattern; - } - - public boolean isShortContext() - { - return shortContext; - } - - public void setShortContext(boolean shortContext) - { - this.shortContext = shortContext; - } - - public void traced(OMTraceHandlerEvent event) - { - String line = pattern == null ? format(shortContext, event) : format(pattern, event); - stream.println(line); - if (event.getThrowable() != null) - { - IOUtil.print(event.getThrowable(), stream); - } - } - - public static String format(boolean shortContext, OMTraceHandlerEvent event) - { - Class<?> context = event.getContext(); - String contextName = shortContext ? context.getSimpleName() : context.getName(); - return Thread.currentThread().getName() + " [" + contextName + "] " + event.getMessage(); - } - - /** - * Pattern arguments: - * <p> - * <ul> - * <li>{0} --> String <b>tracerName</b><br> - * <li>{1} --> String <b>tracerShort</b><br> - * <li>{2} --> String <b>contextName</b><br> - * <li>{3} --> String <b>contextShort</b><br> - * <li>{4} --> long <b>timeStamp</b><br> - * <li>{5} --> String <b>message</b><br> - * <li>{6} --> String <b>threadName</b><br> - * <li>{7} --> long <b>threadID</b><br> - * <li>{8} --> int <b>threadPriority</b><br> - * <li>{9} --> Thread.State <b>threadState</b><br> - * </ul> - */ - public static String format(String pattern, OMTraceHandlerEvent event) - { - final OMTracer tracer = event.getTracer(); - final String tracerName = tracer.getFullName(); - final String tracerShort = tracer.getName(); - - final Class<?> context = event.getContext(); - final String contextName = context.getName(); - final String contextShort = context.getName(); - - final long timeStamp = event.getTimeStamp(); - final String message = event.getMessage(); - - final Thread thread = Thread.currentThread(); - final String threadName = thread.getName(); - final long threadID = thread.getId(); - final int threadPriority = thread.getPriority(); - final Thread.State threadState = thread.getState(); - - return MessageFormat.format(pattern, tracerName, tracerShort, contextName, contextShort, timeStamp, message, - threadName, threadID, threadPriority, threadState); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java deleted file mode 100644 index 50f0299e23..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java +++ /dev/null @@ -1,149 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.util.io.IOUtil; -import org.eclipse.net4j.util.om.trace.OMTraceHandler; -import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; -import java.util.UUID; - -/** - * @author Eike Stepper - */ -public class RemoteTraceHandler implements OMTraceHandler -{ - public static final String DEFAULT_HOST = "localhost"; //$NON-NLS-1$ - - public static final int DEFAULT_PORT = RemoteTraceServer.DEFAULT_PORT; - - private static int uniqueCounter; - - private String agentID; - - private String host; - - private int port; - - private Socket socket; - - public RemoteTraceHandler() throws IOException - { - this(uniqueAgentID()); - } - - public RemoteTraceHandler(String agentID) throws IOException - { - this(agentID, DEFAULT_HOST); - } - - public RemoteTraceHandler(String agentID, String host) throws IOException - { - this(agentID, host, DEFAULT_PORT); - } - - public RemoteTraceHandler(String agentID, String host, int port) throws IOException - { - this.agentID = agentID; - this.host = host; - this.port = port; - socket = connect(); - } - - public Exception close() - { - try - { - socket.close(); - return null; - } - catch (IOException ex) - { - OM.LOG.error(ex); - return ex; - } - } - - public void traced(OMTraceHandlerEvent event) - { - try - { - OutputStream outputStream = socket.getOutputStream(); - DataOutputStream out = new DataOutputStream(outputStream); - - out.writeLong(event.getTimeStamp()); - writeUTF(out, agentID); - writeUTF(out, event.getTracer().getBundle().getBundleID()); - writeUTF(out, event.getTracer().getFullName()); - writeUTF(out, event.getContext() == null ? "" : event.getContext().getName()); - writeUTF(out, event.getMessage()); - if (event.getThrowable() == null) - { - out.writeBoolean(false); - } - else - { - out.writeBoolean(true); - String message = event.getThrowable().getMessage(); - writeUTF(out, message); - - StackTraceElement[] stackTrace = event.getThrowable().getStackTrace(); - int size = stackTrace == null ? 0 : stackTrace.length; - out.writeInt(size); - - for (int i = 0; i < size; i++) - { - StackTraceElement element = stackTrace[i]; - writeUTF(out, element.getClassName()); - writeUTF(out, element.getMethodName()); - writeUTF(out, element.getFileName()); - out.writeInt(element.getLineNumber()); - } - } - - out.flush(); - } - catch (IOException ex) - { - IOUtil.print(ex); - } - } - - protected Socket connect() throws IOException - { - return new Socket(host, port); - } - - protected void writeUTF(DataOutputStream out, String str) throws IOException - { - out.writeUTF(str == null ? "" : str); - } - - public static String uniqueAgentID() - { - try - { - InetAddress localMachine = InetAddress.getLocalHost(); - return localMachine.getHostName() + "#" + ++uniqueCounter; - } - catch (Exception ex) - { - UUID uuid = UUID.randomUUID(); - return uuid.toString(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceServer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceServer.java deleted file mode 100644 index 953aba0854..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceServer.java +++ /dev/null @@ -1,389 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.util.io.IOUtil; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.Date; -import java.util.EventObject; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * @author Eike Stepper - */ -public class RemoteTraceServer -{ - public static final String DEFAULT_ADDRESS = "0.0.0.0"; //$NON-NLS-1$ - - public static final int DEFAULT_PORT = 2035; - - public static final int ANY_PORT = 0; - - private static long lastEventID = 0; - - private int port; - - private String address; - - private ServerSocket serverSocket; - - private Queue<Listener> listeners = new ConcurrentLinkedQueue<Listener>(); - - public RemoteTraceServer() throws IOException - { - this(DEFAULT_PORT); - } - - public RemoteTraceServer(int port) throws IOException - { - this(port, DEFAULT_ADDRESS); - } - - public RemoteTraceServer(int port, String address) throws IOException - { - this.port = port; - this.address = address; - serverSocket = bind(); - new Thread("RemoteTraceServer") - { - @Override - public void run() - { - handleConnections(); - } - }.start(); - } - - public void addListener(Listener listener) - { - if (!listeners.contains(listener)) - { - listeners.add(listener); - } - } - - public void removeListener(Listener listener) - { - listeners.remove(listener); - } - - public Exception close() - { - try - { - serverSocket.close(); - return null; - } - catch (IOException ex) - { - OM.LOG.error(ex); - return ex; - } - } - - protected ServerSocket bind() throws IOException - { - InetAddress addr = InetAddress.getByName(this.address); - return new ServerSocket(port, 5, addr); - } - - protected void handleConnections() - { - for (;;) - { - try - { - final Socket socket = serverSocket.accept(); - new Thread() - { - @Override - public void run() - { - handleSession(socket); - } - }.start(); - } - catch (IOException ex) - { - if (!serverSocket.isClosed()) - { - IOUtil.print(ex); - } - - break; - } - } - } - - protected void handleSession(Socket socket) - { - try - { - InputStream inputStream = socket.getInputStream(); - DataInputStream in = new DataInputStream(inputStream); - - for (;;) - { - handleTrace(in); - } - } - catch (IOException ex) - { - IOUtil.print(ex); - } - } - - protected void handleTrace(DataInputStream in) throws IOException - { - Event event = new Event(); - event.timeStamp = in.readLong(); - event.agentID = in.readUTF(); - event.bundleID = in.readUTF(); - event.tracerName = in.readUTF(); - event.context = in.readUTF(); - event.message = in.readUTF(); - if (in.readBoolean()) - { - event.throwable = in.readUTF(); - int size = in.readInt(); - event.stackTrace = new StackTraceElement[size]; - for (int i = 0; i < size; i++) - { - String className = in.readUTF(); - String methodName = in.readUTF(); - String fileName = in.readUTF(); - int lineNumber = in.readInt(); - event.stackTrace[i] = new StackTraceElement(className, methodName, fileName, lineNumber); - } - } - - fireEvent(event); - } - - protected void fireEvent(Event event) - { - for (Listener listener : listeners) - { - try - { - listener.notifyRemoteTrace(event); - } - catch (RuntimeException ex) - { - IOUtil.print(ex); - } - } - } - - /** - * @author Eike Stepper - */ - public class Event extends EventObject - { - private static final long serialVersionUID = 1L; - - private long id; - - long timeStamp; - - String agentID; - - String bundleID; - - String tracerName; - - String context; - - String message; - - String throwable; - - StackTraceElement[] stackTrace; - - Event() - { - super(RemoteTraceServer.this); - id = ++lastEventID; - } - - public RemoteTraceServer getRemoteTraceServer() - { - return (RemoteTraceServer)source; - } - - public long getID() - { - return id; - } - - public long getTimeStamp() - { - return timeStamp; - } - - public String getAgentID() - { - return agentID; - } - - public String getBundleID() - { - return bundleID; - } - - public String getContext() - { - return context; - } - - public String getMessage() - { - return message; - } - - public StackTraceElement[] getStackTrace() - { - return stackTrace; - } - - public String getThrowable() - { - return throwable; - } - - public String getTracerName() - { - return tracerName; - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("TraceEvent[agentID="); - builder.append(agentID); - - builder.append(", bundleID="); - builder.append(bundleID); - - builder.append(", tracerName="); - builder.append(tracerName); - - builder.append(", context="); - builder.append(context); - - builder.append(", message="); - builder.append(message); - - builder.append(", throwable="); - builder.append(throwable); - - builder.append(", stackTrace="); - builder.append(stackTrace); - - builder.append("]"); - return builder.toString(); - } - - public String getText(int index) - { - switch (index) - { - case 0: - return Long.toString(id); - case 1: - return new Date(timeStamp).toString(); - case 2: - return agentID; - case 3: - return bundleID; - case 4: - return tracerName; - case 5: - return context; - case 6: - return message; - case 7: - return throwable; - } - - throw new IllegalArgumentException("Invalid index: " + index); - } - - public boolean hasError() - { - return throwable != null && throwable.length() != 0 // - || stackTrace != null && stackTrace.length != 0; - } - - } - - /** - * @author Eike Stepper - */ - public interface Listener - { - public void notifyRemoteTrace(Event event); - } - - public static class PrintListener implements Listener - { - public static final PrintListener CONSOLE = new PrintListener(); - - private PrintStream stream; - - public PrintListener(PrintStream stream) - { - this.stream = stream; - } - - protected PrintListener() - { - this(IOUtil.OUT()); - } - - public void notifyRemoteTrace(Event event) - { - stream.println("[TRACE] " + event.getAgentID()); - stream.println(event.getBundleID()); - stream.println(event.getTracerName()); - stream.println(event.getContext()); - stream.println(event.getMessage()); - - String throwable = event.getThrowable(); - if (throwable != null && throwable.length() != 0) - { - stream.println(throwable); - } - - StackTraceElement[] stackTrace = event.getStackTrace(); - if (stackTrace != null) for (StackTraceElement element : stackTrace) - { - stream.print(element.getClassName()); - stream.print("." + element.getMethodName()); - stream.print("(" + element.getFileName()); - stream.print(":" + element.getLineNumber()); - stream.println(")"); - } - - stream.println(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/TraceHandlerEvent.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/TraceHandlerEvent.java deleted file mode 100644 index 30253d1f10..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/TraceHandlerEvent.java +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent; -import org.eclipse.net4j.util.om.trace.OMTracer; - -import java.io.Serializable; - -/** - * @author Eike Stepper - */ -public class TraceHandlerEvent implements OMTraceHandlerEvent, Serializable -{ - private static final long serialVersionUID = 1L; - - protected long timeStamp; - - protected OMTracer tracer; - - protected Class<?> context; - - protected String message; - - protected Throwable throwable; - - public TraceHandlerEvent(OMTracer tracer, Class<?> context, String message, Throwable throwable) - { - if (tracer == null) - { - throw new IllegalArgumentException("tracer == null"); - } - - if (context == null) - { - throw new IllegalArgumentException("context == null"); - } - - timeStamp = System.currentTimeMillis(); - this.tracer = tracer; - this.context = context; - this.message = message; - this.throwable = throwable; - } - - public long getTimeStamp() - { - return timeStamp; - } - - public OMTracer getTracer() - { - return tracer; - } - - public Class<?> getContext() - { - return context; - } - - public String getMessage() - { - return message; - } - - public Throwable getThrowable() - { - return throwable; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java deleted file mode 100644 index a491d8caf0..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/Tracer.java +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.om.trace; - -import org.eclipse.net4j.internal.util.bundle.AbstractPlatform; -import org.eclipse.net4j.util.om.OMBundle; -import org.eclipse.net4j.util.om.OMBundle.DebugSupport; -import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent; -import org.eclipse.net4j.util.om.trace.OMTracer; - -import java.text.MessageFormat; - -/** - * @author Eike Stepper - */ -public class Tracer implements OMTracer -{ - private OMBundle bundle; - - private Tracer parent; - - private String name; - - private String fullName; - - public Tracer(OMBundle bundle, String name) - { - this.bundle = bundle; - this.name = name; - fullName = name; - } - - private Tracer(Tracer parent, String name) - { - bundle = parent.getBundle(); - this.parent = parent; - this.name = name; - fullName = parent.getFullName() + "." + name; //$NON-NLS-1$ - } - - public OMBundle getBundle() - { - return bundle; - } - - public OMTracer getParent() - { - return parent; - } - - public String getName() - { - return name; - } - - public String getFullName() - { - return fullName; - } - - public boolean isEnabled() - { - DebugSupport debugSupport = bundle.getDebugSupport(); - return debugSupport.isDebugging() && debugSupport.getDebugOption(fullName, false); - } - - public void setEnabled(boolean enabled) - { - DebugSupport debugSupport = bundle.getDebugSupport(); - debugSupport.setDebugOption(fullName, enabled); - } - - public void trace(OMTraceHandlerEvent event) - { - ((AbstractPlatform)bundle.getPlatform()).trace(event); - } - - public OMTraceHandlerEvent trace(Class<?> context, String msg, Throwable t) - { - OMTraceHandlerEvent event = new TraceHandlerEvent(this, context, msg, t); - trace(event); - return event; - } - - public OMTraceHandlerEvent format(Class<?> context, String pattern, Throwable t, Object... args) - { - String msg = MessageFormat.format(pattern, args); - return trace(context, msg, t); - } - - public OMTraceHandlerEvent format(Class<?> context, String pattern, Object... args) - { - return format(context, pattern, (Throwable)null, args); - } - - public OMTraceHandlerEvent trace(Class<?> context, String msg) - { - return trace(context, msg, (Throwable)null); - } - - public OMTraceHandlerEvent trace(Class<?> context, Throwable t) - { - return trace(context, (String)null, t); - } - - public OMTracer tracer(String name) - { - return new Tracer(this, name); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/DelegatingRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/DelegatingRegistry.java deleted file mode 100644 index 46b7f91f12..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/DelegatingRegistry.java +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.registry; - -import org.eclipse.net4j.util.registry.IRegistry; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Implementation note: AbstractDelegatingRegistry does not preserve the "modifyable view" contract of - * {@link Map#entrySet()} as well as of {@link Map#keySet()}, i.e. they are disconnected sets and modifications applied - * to them are not applied to their underlying AbstractDelegatingRegistry. - * <p> - * - * @author Eike Stepper - */ -public abstract class DelegatingRegistry<K, V> extends Registry<K, V> -{ - private IRegistry<K, V> delegate; - - public DelegatingRegistry(IRegistry<K, V> delegate) - { - this.delegate = delegate; - } - - public DelegatingRegistry(IRegistry<K, V> delegate, boolean autoCommit) - { - super(autoCommit); - this.delegate = delegate; - } - - @Override - public V get(Object key) - { - V result = getMap().get(key); - if (result == null && delegate != null) - { - result = delegate.get(key); - } - - return result; - } - - @Override - public Set<Entry<K, V>> entrySet() - { - return mergedEntrySet(); - } - - @Override - public Set<K> keySet() - { - return mergedKeySet(); - } - - @Override - public Collection<V> values() - { - return mergedValues(); - } - - @Override - protected V register(K key, V value) - { - V delegated = delegate != null ? delegate.get(key) : null; - V old = getMap().put(key, value); - if (old == null) - { - if (delegated != null) - { - // Unhidden delegated element now becomes hidden - getTransaction().rememberDeregistered(key, delegated); - } - - getTransaction().rememberRegistered(key, value); - return delegated; - } - - getTransaction().rememberDeregistered(key, old); - getTransaction().rememberRegistered(key, value); - return old; - } - - @SuppressWarnings("unchecked") - @Override - protected V deregister(Object key) - { - V delegated = delegate != null ? delegate.get(key) : null; - V old = getMap().remove(key); - if (old != null) - { - getTransaction().rememberDeregistered((K)key, old); - if (delegated != null) - { - // Hidden delegated element now becomes unhidden - getTransaction().rememberRegistered((K)key, delegated); - } - } - - return old; - } - - protected Set<Entry<K, V>> mergedEntrySet() - { - final Map<K, V> merged = new HashMap<K, V>(); - if (delegate != null) - { - merged.putAll(delegate); - } - - merged.putAll(getMap()); - return merged.entrySet(); - } - - protected Set<K> mergedKeySet() - { - final Set<K> merged = new HashSet<K>(); - if (delegate != null) - { - merged.addAll(delegate.keySet()); - } - - merged.addAll(getMap().keySet()); - return merged; - } - - protected Collection<V> mergedValues() - { - final List<V> result = new ArrayList<V>(); - for (K key : keySet()) - { - result.add(get(key)); - } - - return result; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapDelegatingRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapDelegatingRegistry.java deleted file mode 100644 index b7ccd2e3f6..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapDelegatingRegistry.java +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.registry; - -import org.eclipse.net4j.util.registry.IRegistry; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class HashMapDelegatingRegistry<K, V> extends DelegatingRegistry<K, V> -{ - private Map<K, V> map; - - public HashMapDelegatingRegistry(IRegistry<K, V> delegate) - { - super(delegate); - map = new HashMap<K, V>(); - } - - public HashMapDelegatingRegistry(IRegistry<K, V> delegate, int initialCapacity) - { - super(delegate); - map = new HashMap<K, V>(initialCapacity); - } - - public HashMapDelegatingRegistry(IRegistry<K, V> delegate, int initialCapacity, float loadFactor) - { - super(delegate); - map = new HashMap<K, V>(initialCapacity, loadFactor); - } - - public HashMapDelegatingRegistry(IRegistry<K, V> delegate, Map<? extends K, ? extends V> m) - { - super(delegate); - map = new HashMap<K, V>(m); - } - - @Override - protected Map<K, V> getMap() - { - return map; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapRegistry.java deleted file mode 100644 index 9515fe0f6b..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/HashMapRegistry.java +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.registry; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class HashMapRegistry<K, V> extends Registry<K, V> -{ - private Map<K, V> map; - - public HashMapRegistry() - { - map = new HashMap<K, V>(); - } - - public HashMapRegistry(int initialCapacity) - { - map = new HashMap<K, V>(initialCapacity); - } - - public HashMapRegistry(int initialCapacity, float loadFactor) - { - map = new HashMap<K, V>(initialCapacity, loadFactor); - } - - public HashMapRegistry(Map<? extends K, ? extends V> m) - { - map = new HashMap<K, V>(m); - } - - @Override - protected Map<K, V> getMap() - { - return map; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/Registry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/Registry.java deleted file mode 100644 index 9b692dc1e3..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/Registry.java +++ /dev/null @@ -1,328 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.registry; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.internal.util.container.Container; -import org.eclipse.net4j.internal.util.container.ContainerEvent; -import org.eclipse.net4j.util.container.IContainerDelta; -import org.eclipse.net4j.util.registry.IRegistry; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * @author Eike Stepper - */ -public abstract class Registry<K, V> extends Container<Map.Entry<K, V>> implements IRegistry<K, V> -{ - private boolean autoCommit; - - private Transaction transaction; - - protected Registry(boolean autoCommit) - { - this.autoCommit = autoCommit; - } - - protected Registry() - { - this(true); - } - - @Override - public boolean isEmpty() - { - return keySet().isEmpty(); - } - - public int size() - { - return keySet().size(); - } - - public Set<Entry<K, V>> entrySet() - { - return getMap().entrySet(); - } - - public Set<K> keySet() - { - return getMap().keySet(); - } - - public Collection<V> values() - { - return getMap().values(); - } - - public boolean containsKey(Object key) - { - return keySet().contains(key); - } - - public boolean containsValue(Object value) - { - return values().contains(value); - } - - public V get(Object key) - { - return getMap().get(key); - } - - /** - * Requires {@link #commit()} to be called later if not {@link #isAutoCommit()}. - */ - public synchronized V put(K key, V value) - { - V result = register(key, value); - autoCommit(); - return result; - } - - /** - * Requires {@link #commit()} to be called later if not {@link #isAutoCommit()}. - */ - public synchronized void putAll(Map<? extends K, ? extends V> t) - { - if (!t.isEmpty()) - { - Iterator<? extends Entry<? extends K, ? extends V>> i = t.entrySet().iterator(); - while (i.hasNext()) - { - Entry<? extends K, ? extends V> e = i.next(); - register(e.getKey(), e.getValue()); - } - - autoCommit(); - } - } - - /** - * Requires {@link #commit()} to be called later if not {@link #isAutoCommit()}. - */ - public synchronized V remove(Object key) - { - V result = deregister(key); - autoCommit(); - return result; - } - - /** - * Requires {@link #commit()} to be called later if not {@link #isAutoCommit()}. - */ - public synchronized void clear() - { - if (!isEmpty()) - { - for (Object key : keySet().toArray()) - { - deregister(key); - } - - autoCommit(); - } - } - - @SuppressWarnings("unchecked") - public Entry<K, V>[] getElements() - { - return entrySet().toArray(new Entry[size()]); - } - - public boolean isAutoCommit() - { - return autoCommit; - } - - public void setAutoCommit(boolean autoCommit) - { - this.autoCommit = autoCommit; - } - - public synchronized void commit(boolean notifications) - { - if (transaction != null) - { - if (!transaction.isOwned()) - { - OM.LOG.warn("Committing thread is not owner of transaction: " + Thread.currentThread()); - } - - transaction.commit(notifications); - transaction = null; - notifyAll(); - } - } - - public void commit() - { - commit(true); - } - - @Override - public String toString() - { - return getMap().toString(); - } - - protected V register(K key, V value) - { - Transaction transaction = getTransaction(); - V oldValue = getMap().put(key, value); - if (oldValue != null) - { - transaction.rememberDeregistered(key, oldValue); - } - - transaction.rememberRegistered(key, value); - return oldValue; - } - - @SuppressWarnings("unchecked") - protected V deregister(Object key) - { - V value = getMap().remove(key); - if (value != null) - { - getTransaction().rememberDeregistered((K)key, value); - } - - return value; - } - - protected Transaction getTransaction() - { - for (;;) - { - if (transaction == null) - { - transaction = new Transaction(); - return transaction; - } - - if (transaction.isOwned()) - { - transaction.increaseNesting(); - return transaction; - } - - try - { - wait(); - } - catch (InterruptedException ex) - { - return null; - } - } - } - - protected void autoCommit() - { - if (autoCommit) - { - commit(); - } - } - - protected abstract Map<K, V> getMap(); - - /** - * @author Eike Stepper - */ - protected class Transaction - { - private int nesting = 1; - - private ContainerEvent<Map.Entry<K, V>> event; - - private Thread owner; - - public Transaction() - { - owner = Thread.currentThread(); - initEvent(); - } - - private void initEvent() - { - event = newContainerEvent(); - } - - public boolean isOwned() - { - return owner == Thread.currentThread(); - } - - public void increaseNesting() - { - ++nesting; - } - - public void commit(boolean notifications) - { - if (--nesting == 0) - { - if (notifications && !event.isEmpty()) - { - fireEvent(event); - } - - initEvent(); - } - } - - public void rememberRegistered(K key, V value) - { - event.addDelta(new Element<K, V>(key, value), IContainerDelta.Kind.ADDED); - } - - public void rememberDeregistered(K key, V value) - { - event.addDelta(new Element<K, V>(key, value), IContainerDelta.Kind.REMOVED); - } - } - - /** - * @author Eike Stepper - */ - private static final class Element<K, V> implements Map.Entry<K, V> - { - private final K key; - - private final V value; - - private Element(K key, V value) - { - this.key = key; - this.value = value; - } - - public K getKey() - { - return key; - } - - public V getValue() - { - return value; - } - - public V setValue(V value) - { - throw new UnsupportedOperationException(); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/UnmodifiableRegistry.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/UnmodifiableRegistry.java deleted file mode 100644 index 84fb9a4576..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/registry/UnmodifiableRegistry.java +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.registry; - -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.registry.IRegistry; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -public class UnmodifiableRegistry<K, V> implements IRegistry<K, V> -{ - private IRegistry<K, V> delegate; - - public UnmodifiableRegistry(IRegistry<K, V> delegate) - { - this.delegate = delegate; - } - - public void addListener(IListener listener) - { - delegate.addListener(listener); - } - - public void removeListener(IListener listener) - { - delegate.removeListener(listener); - } - - public V put(K key, V value) - { - throw new UnsupportedOperationException(); - } - - public void putAll(Map<? extends K, ? extends V> t) - { - throw new UnsupportedOperationException(); - } - - public V remove(Object key) - { - throw new UnsupportedOperationException(); - } - - public void clear() - { - throw new UnsupportedOperationException(); - } - - public void commit() - { - throw new UnsupportedOperationException(); - } - - public void commit(boolean notifications) - { - throw new UnsupportedOperationException(); - } - - public void setAutoCommit(boolean on) - { - throw new UnsupportedOperationException(); - } - - public boolean isAutoCommit() - { - return delegate.isAutoCommit(); - } - - public boolean isEmpty() - { - return delegate.isEmpty(); - } - - public int size() - { - return delegate.size(); - } - - public Entry<K, V>[] getElements() - { - return delegate.getElements(); - } - - public V get(Object key) - { - return delegate.get(key); - } - - public boolean containsKey(Object key) - { - return delegate.containsKey(key); - } - - public boolean containsValue(Object value) - { - return delegate.containsValue(value); - } - - public Set<Entry<K, V>> entrySet() - { - return delegate.entrySet(); - } - - public Set<K> keySet() - { - return delegate.keySet(); - } - - public Collection<V> values() - { - return delegate.values(); - } - - public boolean equals(Object o) - { - return delegate.equals(o); - } - - public int hashCode() - { - return delegate.hashCode(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java deleted file mode 100644 index adad8a793c..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java +++ /dev/null @@ -1,145 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.security.INegotiationContext; -import org.eclipse.net4j.util.security.IRandomizer; -import org.eclipse.net4j.util.security.IUserManager; - -import java.nio.ByteBuffer; -import java.util.Arrays; - -/** - * @author Eike Stepper - */ -public class ChallengeNegotiator extends ChallengeResponseNegotiator -{ - public static final int DEFAULT_TOKEN_LENGTH = 1024; - - private int tokenLength = DEFAULT_TOKEN_LENGTH; - - private IRandomizer randomizer; - - private IUserManager userManager; - - public ChallengeNegotiator() - { - super(true); - } - - public int getTokenLength() - { - return tokenLength; - } - - public void setTokenLength(int tokenLength) - { - this.tokenLength = tokenLength; - } - - public IRandomizer getRandomizer() - { - return randomizer; - } - - public void setRandomizer(IRandomizer randomizer) - { - this.randomizer = randomizer; - } - - public IUserManager getUserManager() - { - return userManager; - } - - public void setUserManager(IUserManager userManager) - { - this.userManager = userManager; - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (tokenLength <= 0) - { - throw new IllegalStateException("tokenLength must be positive"); - } - - if (randomizer == null) - { - throw new IllegalStateException("randomizer == null"); - } - - if (userManager == null) - { - throw new IllegalStateException("userManager == null"); - } - } - - protected byte[] createRandomToken() - { - byte[] token = new byte[tokenLength]; - randomizer.nextBytes(token); - return token; - } - - protected byte[] encryptToken(String userID, byte[] token) throws SecurityException - { - return userManager.encrypt(userID, token, getAlgorithmName()); - } - - @Override - protected void createChallenge(INegotiationContext context, ByteBuffer challenge) - { - // Create and remember a random token - byte[] randomToken = createRandomToken(); - context.setInfo(randomToken); - - // Set the token into challenge - challenge.putInt(randomToken.length); - challenge.put(randomToken); - } - - @Override - protected void handleChallenge(INegotiationContext context, ByteBuffer challenge, ByteBuffer response) - { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean handleResponse(INegotiationContext context, ByteBuffer response) - { - // Get remembered random token - byte[] randomToken = (byte[])context.getInfo(); - - // Get userID from response - int size = response.getInt(); - byte[] userIDBytes = new byte[size]; - response.get(userIDBytes); - String userID = new String(userIDBytes); - - // Get crypted token from response - size = response.getInt(); - byte[] responseToken = new byte[size]; - response.get(responseToken); - - // Encrypt the remembered token and compare to crypted token from response - byte[] cryptedToken = encryptToken(userID, randomToken); - boolean success = Arrays.equals(responseToken, cryptedToken); - if (success) - { - context.setUserID(userID); - } - - return success; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorConfigurer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorConfigurer.java deleted file mode 100644 index 234091d592..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorConfigurer.java +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.container.IElementProcessor; -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.security.IRandomizer; -import org.eclipse.net4j.util.security.IUserManager; - -/** - * @author Eike Stepper - */ -public class ChallengeNegotiatorConfigurer implements IElementProcessor -{ - public ChallengeNegotiatorConfigurer() - { - } - - public Object process(IManagedContainer container, String productGroup, String factoryType, String description, - Object element) - { - if (element instanceof ChallengeNegotiator) - { - ChallengeNegotiator negotiator = (ChallengeNegotiator)element; - if (negotiator.getRandomizer() == null) - { - IRandomizer randomizer = getRandomizer(container, description); - negotiator.setRandomizer(randomizer); - } - - if (negotiator.getUserManager() == null) - { - IUserManager userManager = getUserManager(container, description); - negotiator.setUserManager(userManager); - } - } - - return element; - } - - protected IRandomizer getRandomizer(IManagedContainer container, String description) - { - String productGroup = RandomizerFactory.PRODUCT_GROUP; - String type = getRandomizerType(description); - return (IRandomizer)container.getElement(productGroup, type, getRandomizerDescription(description)); - } - - protected String getRandomizerType(String description) - { - return RandomizerFactory.TYPE; - } - - protected String getRandomizerDescription(String description) - { - return null; - } - - protected IUserManager getUserManager(IManagedContainer container, String description) - { - String productGroup = FileUserManagerFactory.PRODUCT_GROUP; - String type = getUserManagerType(description); - return (IUserManager)container.getElement(productGroup, type, getUserManagerDescription(description)); - } - - protected String getUserManagerType(String description) - { - return FileUserManagerFactory.TYPE; - } - - protected String getUserManagerDescription(String description) - { - return description; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorFactory.java deleted file mode 100644 index 7e48893eb2..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiatorFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -/** - * @author Eike Stepper - */ -public class ChallengeNegotiatorFactory extends NegotiatorFactory -{ - public static final String TYPE = "challenge"; - - public ChallengeNegotiatorFactory() - { - super(TYPE); - } - - public ChallengeNegotiator create(String description) - { - return new ChallengeNegotiator(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java deleted file mode 100644 index df841c5e4d..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.fsm.ITransition; -import org.eclipse.net4j.util.security.IChallengeResponse; -import org.eclipse.net4j.util.security.INegotiationContext; -import org.eclipse.net4j.util.security.SecurityUtil; - -import java.nio.ByteBuffer; - -/** - * @author Eike Stepper - */ -public abstract class ChallengeResponseNegotiator extends - Negotiator<IChallengeResponse.State, IChallengeResponse.Event> implements IChallengeResponse -{ - public static final String DEFAULT_ALGORITHM_NAME = SecurityUtil.PBE_WITH_MD5_AND_DES; - - private String algorithmName = DEFAULT_ALGORITHM_NAME; - - public ChallengeResponseNegotiator(boolean initiator) - { - super(State.class, Event.class, State.INITIAL, State.SUCCESS, State.FAILURE, Event.START, Event.BUFFER, initiator); - - init(State.INITIAL, Event.START, new Transition() - { - @Override - protected void execute(INegotiationContext context, ByteBuffer NULL) - { - // Create and transmit challenge - ByteBuffer challenge = context.getBuffer(); - createChallenge(context, challenge); - context.transmitBuffer(challenge); - - // Set context state - changeState(context, State.CHALLENGE); - } - }); - - init(State.INITIAL, Event.BUFFER, new Transition() - { - @Override - protected void execute(INegotiationContext context, ByteBuffer challenge) - { - // Handle challenge and transmit response - ByteBuffer response = context.getBuffer(); - handleChallenge(context, challenge, response); - context.transmitBuffer(response); - - // Set context state - changeState(context, State.RESPONSE); - } - }); - - init(State.CHALLENGE, Event.BUFFER, new Transition() - { - @Override - protected void execute(INegotiationContext context, ByteBuffer response) - { - // Handle response - boolean success = handleResponse(context, response); - - // Transmit acknowledgement - ByteBuffer acknowledgement = context.getBuffer(); - acknowledgement.put(success ? ACKNOWLEDGE_SUCCESS : ACKNOWLEDGE_FAILURE); - context.transmitBuffer(acknowledgement); - - // Set context state - changeState(context, success ? State.SUCCESS : State.FAILURE); - } - }); - - init(State.RESPONSE, Event.BUFFER, new Transition() - { - @Override - protected void execute(INegotiationContext context, ByteBuffer acknowledgement) - { - // Handle acknowledgement - boolean success = acknowledgement.get() == ACKNOWLEDGE_SUCCESS; - - // Set context state - changeState(context, success ? State.SUCCESS : State.FAILURE); - } - }); - } - - public String getAlgorithmName() - { - return algorithmName; - } - - public void setAlgorithmName(String algorithmName) - { - this.algorithmName = algorithmName; - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (algorithmName == null) - { - throw new IllegalStateException("algorithmName == null"); - } - } - - @Override - protected State getState(INegotiationContext subject) - { - return (State)subject.getState(); - } - - @Override - protected void setState(INegotiationContext subject, State state) - { - subject.setState(state); - } - - protected abstract void createChallenge(INegotiationContext context, ByteBuffer challenge); - - protected abstract void handleChallenge(INegotiationContext context, ByteBuffer challenge, ByteBuffer response); - - protected abstract boolean handleResponse(INegotiationContext context, ByteBuffer response); - - /** - * @author Eike Stepper - */ - protected abstract class Transition implements ITransition<State, Event, INegotiationContext, ByteBuffer> - { - public final void execute(INegotiationContext context, State state, Event event, ByteBuffer buffer) - { - execute(context, buffer); - } - - protected abstract void execute(INegotiationContext context, ByteBuffer buffer); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java deleted file mode 100644 index 01ed0852ae..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.security.ICredentials; - -/** - * @author Eike Stepper - */ -public class Credentials implements ICredentials -{ - private String userID; - - public Credentials(String userID) - { - this.userID = userID; - } - - public String getUserID() - { - return userID; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java deleted file mode 100644 index 9007fbb682..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.io.IORuntimeException; -import org.eclipse.net4j.util.io.IOUtil; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.text.MessageFormat; -import java.util.Map; -import java.util.Properties; -import java.util.Map.Entry; - -/** - * @author Eike Stepper - */ -public class FileUserManager extends UserManager -{ - protected String fileName; - - public FileUserManager() - { - } - - public String getFileName() - { - return fileName; - } - - public void setFileName(String fileName) - { - this.fileName = fileName; - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (fileName == null) - { - throw new IllegalStateException("fileName == null"); - } - - File file = new File(fileName); - if (file.exists() && !file.isFile()) - { - throw new IllegalStateException("Not a file: " + fileName); - } - } - - @Override - protected void load(Map<String, char[]> users) throws IORuntimeException - { - File file = new File(fileName); - if (!file.exists()) - { - return; - } - - FileInputStream stream = IOUtil.openInputStream(new File(fileName)); - try - { - load(users, stream); - } - catch (IOException ex) - { - throw new IORuntimeException(ex); - } - finally - { - IOUtil.closeSilent(stream); - } - } - - protected void load(Map<String, char[]> users, InputStream stream) throws IOException - { - Properties properties = new Properties(); - properties.load(stream); - for (Entry<Object, Object> entry : properties.entrySet()) - { - String userID = (String)entry.getKey(); - char[] password = ((String)entry.getValue()).toCharArray(); - users.put(userID, password); - } - } - - @Override - protected void save(Map<String, char[]> users) throws IORuntimeException - { - File file = new File(fileName); - if (!file.exists()) - { - return; - } - - FileOutputStream stream = IOUtil.openOutputStream(new File(fileName)); - try - { - save(users, stream); - } - catch (IOException ex) - { - throw new IORuntimeException(ex); - } - finally - { - IOUtil.closeSilent(stream); - } - } - - protected void save(Map<String, char[]> users, FileOutputStream stream) throws IOException - { - Properties properties = new Properties(); - for (Entry<String, char[]> entry : users.entrySet()) - { - properties.put(entry.getKey(), new String(entry.getValue())); - } - - String comment = MessageFormat.format("User database {0,date} {0,time}", System.currentTimeMillis()); - properties.store(stream, comment); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManagerFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManagerFactory.java deleted file mode 100644 index 99c244e5a5..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManagerFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -/** - * TODO Consider file attributes when creating initially empty file - * - * @author Eike Stepper - */ -public class FileUserManagerFactory extends UserManagerFactory -{ - public static final String TYPE = "file"; - - public FileUserManagerFactory() - { - super(TYPE); - } - - public FileUserManager create(String description) - { - FileUserManager userManager = new FileUserManager(); - userManager.setFileName(description); - return userManager; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java deleted file mode 100644 index a5e8c6b621..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.WrappedException; -import org.eclipse.net4j.util.security.INegotiationContext; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * @author Eike Stepper - */ -public abstract class NegotiationContext implements INegotiationContext -{ - private Receiver receiver; - - private Enum<?> state; - - private Object info; - - private CountDownLatch finishedLatch = new CountDownLatch(1); - - public NegotiationContext() - { - } - - public Receiver getReceiver() - { - return receiver; - } - - public void setReceiver(Receiver receiver) - { - this.receiver = receiver; - } - - public Enum<?> getState() - { - return state; - } - - public void setState(Enum<?> state) - { - this.state = state; - } - - public Object getInfo() - { - return info; - } - - public void setInfo(Object info) - { - this.info = info; - } - - public void setFinished(boolean success) - { - if (finishedLatch != null) - { - finishedLatch.countDown(); - } - } - - public Enum<?> waitUntilFinished(long timeout) - { - if (finishedLatch == null) - { - throw new IllegalStateException("finishedLatch == null"); - } - - try - { - if (timeout == -1) - { - finishedLatch.await(); - } - else - { - finishedLatch.await(timeout, TimeUnit.MILLISECONDS); - } - } - catch (InterruptedException ex) - { - throw WrappedException.wrap(ex); - } - finally - { - finishedLatch = null; - } - - return state; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java deleted file mode 100644 index 03974ad530..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.fsm.FiniteStateMachine; -import org.eclipse.net4j.util.security.INegotiationContext; -import org.eclipse.net4j.util.security.INegotiator; - -import java.nio.ByteBuffer; - -/** - * @author Eike Stepper - */ -public abstract class Negotiator<STATE extends Enum<?>, EVENT extends Enum<?>> extends - FiniteStateMachine<STATE, EVENT, INegotiationContext> implements INegotiator, INegotiationContext.Receiver -{ - private transient STATE initialState; - - private transient STATE successState; - - private transient STATE failureState; - - private transient EVENT startEvent; - - private transient EVENT bufferEvent; - - private boolean initiator; - - public Negotiator(Class<STATE> stateEnum, Class<EVENT> eventEnum, STATE initialState, STATE successState, - STATE failureState, EVENT startEvent, EVENT bufferEvent, boolean initiator) - { - super(stateEnum, eventEnum); - - if (initialState == null) throw new IllegalStateException("initialState == null"); - if (successState == null) throw new IllegalStateException("successState == null"); - if (failureState == null) throw new IllegalStateException("failureState == null"); - if (startEvent == null) throw new IllegalStateException("startEvent == null"); - if (bufferEvent == null) throw new IllegalStateException("bufferEvent == null"); - - this.initialState = initialState; - this.successState = successState; - this.failureState = failureState; - this.startEvent = startEvent; - this.bufferEvent = bufferEvent; - this.initiator = initiator; - - } - - public STATE getInitialState() - { - return initialState; - } - - public STATE getSuccessState() - { - return successState; - } - - public STATE getFailureState() - { - return failureState; - } - - public EVENT getBufferEvent() - { - return bufferEvent; - } - - public EVENT getStartEvent() - { - return startEvent; - } - - public boolean isInitiator() - { - return initiator; - } - - public void negotiate(INegotiationContext context) - { - context.setReceiver(this); - context.setState(initialState); - if (initiator) - { - process(context, startEvent, null); - postProcess(context); - } - } - - public void receiveBuffer(INegotiationContext context, ByteBuffer buffer) - { - process(context, bufferEvent, buffer); - postProcess(context); - } - - protected void postProcess(INegotiationContext context) - { - Enum<?> state = context.getState(); - if (state == successState) - { - context.setFinished(true); - } - else if (state == failureState) - { - context.setFinished(false); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiatorFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiatorFactory.java deleted file mode 100644 index ee4090c1b5..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiatorFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.internal.util.factory.Factory; - -/** - * @author Eike Stepper - */ -public abstract class NegotiatorFactory extends Factory -{ - public static final String PRODUCT_GROUP = "org.eclipse.net4j.Negotiators"; - - public NegotiatorFactory(String type) - { - super(PRODUCT_GROUP, type); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java deleted file mode 100644 index 94a83fd40e..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.security.IPasswordCredentials; - -/** - * @author Eike Stepper - */ -public class PasswordCredentials extends Credentials implements IPasswordCredentials -{ - private char[] password; - - public PasswordCredentials(String userID, char[] password) - { - super(userID); - this.password = password; - } - - public char[] getPassword() - { - return password; - } - - public void setPassword(char[] password) - { - this.password = password; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentialsProvider.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentialsProvider.java deleted file mode 100644 index 53d392d369..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentialsProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.security.IPasswordCredentials; -import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; - -/** - * @author Eike Stepper - */ -public final class PasswordCredentialsProvider implements IPasswordCredentialsProvider -{ - private IPasswordCredentials credentials; - - public PasswordCredentialsProvider(IPasswordCredentials credentials) - { - this.credentials = credentials; - } - - public boolean isInteractive() - { - return false; - } - - public IPasswordCredentials getCredentials() - { - return credentials; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java deleted file mode 100644 index 7c9b078bad..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java +++ /dev/null @@ -1,159 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.internal.util.lifecycle.Lifecycle; -import org.eclipse.net4j.util.security.IRandomizer; - -import java.security.SecureRandom; - -/** - * @author Eike Stepper - */ -public class Randomizer extends Lifecycle implements IRandomizer -{ - public static final String ALGORITHM_SHA1PRNG = "SHA1PRNG"; - - public static final String DEFAULT_ALGORITHM_NAME = ALGORITHM_SHA1PRNG; - - private String algorithmName = DEFAULT_ALGORITHM_NAME; - - private String providerName; - - private transient SecureRandom secureRandom; - - public String getAlgorithmName() - { - return algorithmName; - } - - public void setAlgorithmName(String algorithmName) - { - this.algorithmName = algorithmName; - } - - public String getProviderName() - { - return providerName; - } - - public void setProviderName(String providerName) - { - this.providerName = providerName; - } - - public boolean nextBoolean() - { - return secureRandom.nextBoolean(); - } - - public double nextDouble() - { - return secureRandom.nextDouble(); - } - - public float nextFloat() - { - return secureRandom.nextFloat(); - } - - public synchronized double nextGaussian() - { - return secureRandom.nextGaussian(); - } - - public int nextInt() - { - return secureRandom.nextInt(); - } - - public int nextInt(int n) - { - return secureRandom.nextInt(n); - } - - public long nextLong() - { - return secureRandom.nextLong(); - } - - public byte[] generateSeed(int numBytes) - { - return secureRandom.generateSeed(numBytes); - } - - public String getAlgorithm() - { - return secureRandom.getAlgorithm(); - } - - public synchronized void nextBytes(byte[] bytes) - { - secureRandom.nextBytes(bytes); - } - - public String nextString(int length, String alphabet) - { - int n = alphabet.length(); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < length; i++) - { - int pos = nextInt(n); - char c = alphabet.charAt(pos); - builder.append(c); - } - - return builder.toString(); - } - - public synchronized void setSeed(byte[] seed) - { - secureRandom.setSeed(seed); - } - - public void setSeed(long seed) - { - secureRandom.setSeed(seed); - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (algorithmName == null) - { - throw new IllegalStateException("algorithmName == null"); - } - } - - @Override - protected void doActivate() throws Exception - { - super.doActivate(); - if (providerName == null) - { - secureRandom = SecureRandom.getInstance(algorithmName); - } - else - { - secureRandom = SecureRandom.getInstance(algorithmName, providerName); - } - - secureRandom.setSeed(System.currentTimeMillis()); - } - - @Override - protected void doDeactivate() throws Exception - { - secureRandom = null; - super.doDeactivate(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/RandomizerFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/RandomizerFactory.java deleted file mode 100644 index 537b8754af..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/RandomizerFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.internal.util.factory.Factory; -import org.eclipse.net4j.util.factory.ProductCreationException; - -/** - * @author Eike Stepper - */ -public class RandomizerFactory extends Factory -{ - public static final String PRODUCT_GROUP = "org.eclipse.net4j.randomizers"; - - public static final String TYPE = "default"; - - public RandomizerFactory() - { - super(PRODUCT_GROUP, TYPE); - } - - public Randomizer create(String description) throws ProductCreationException - { - Randomizer randomizer = new Randomizer(); - if (description != null) - { - randomizer.setAlgorithmName(description); - } - - return randomizer; - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java deleted file mode 100644 index d734a7c25f..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.util.security.INegotiationContext; -import org.eclipse.net4j.util.security.IPasswordCredentials; -import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; -import org.eclipse.net4j.util.security.SecurityUtil; - -import java.nio.ByteBuffer; - -/** - * @author Eike Stepper - */ -public class ResponseNegotiator extends ChallengeResponseNegotiator -{ - private IPasswordCredentialsProvider credentialsProvider; - - public ResponseNegotiator() - { - super(false); - } - - public IPasswordCredentialsProvider getCredentialsProvider() - { - return credentialsProvider; - } - - public void setCredentialsProvider(IPasswordCredentialsProvider credentialsProvider) - { - this.credentialsProvider = credentialsProvider; - } - - @Override - protected void doBeforeActivate() throws Exception - { - super.doBeforeActivate(); - if (credentialsProvider == null) - { - throw new IllegalStateException("credentialsProvider == null"); - } - } - - @Override - protected void createChallenge(INegotiationContext context, ByteBuffer challenge) - { - throw new UnsupportedOperationException(); - } - - @Override - protected void handleChallenge(INegotiationContext context, ByteBuffer challenge, ByteBuffer response) - { - // Get random token from challenge - int size = challenge.getInt(); - byte[] randomToken = new byte[size]; - challenge.get(randomToken); - - // Get credentials and encrypt token - IPasswordCredentials credentials = credentialsProvider.getCredentials(); - String userID = credentials.getUserID(); - context.setUserID(userID); - - // Set userID into response - byte[] userIDBytes = userID.getBytes(); - response.putInt(userIDBytes.length); - response.put(userIDBytes); - - // Set crypted token into response - byte[] cryptedToken = encryptToken(credentials.getPassword(), randomToken); - response.putInt(cryptedToken.length); - response.put(cryptedToken); - } - - @Override - protected boolean handleResponse(INegotiationContext context, ByteBuffer response) - { - throw new UnsupportedOperationException(); - } - - protected byte[] encryptToken(char[] password, byte[] token) - { - try - { - return SecurityUtil.encrypt(token, password, getAlgorithmName()); - } - catch (RuntimeException ex) - { - throw ex; - } - catch (Exception ex) - { - throw new SecurityException(ex); - } - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiatorFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiatorFactory.java deleted file mode 100644 index 12030ce0df..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiatorFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -/** - * @author Eike Stepper - */ -public class ResponseNegotiatorFactory extends NegotiatorFactory -{ - public static final String TYPE = "response"; - - public ResponseNegotiatorFactory() - { - super(TYPE); - } - - public ResponseNegotiator create(String description) - { - return new ResponseNegotiator(); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java deleted file mode 100644 index bec24fa4d0..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.internal.util.lifecycle.Lifecycle; -import org.eclipse.net4j.util.io.IORuntimeException; -import org.eclipse.net4j.util.security.IUserManager; -import org.eclipse.net4j.util.security.SecurityUtil; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class UserManager extends Lifecycle implements IUserManager -{ - // Transient to prevent from logging - protected transient Map<String, char[]> users = new HashMap<String, char[]>(); - - public UserManager() - { - } - - public synchronized void addUser(String userID, char[] password) - { - users.put(userID, password); - save(users); - } - - public synchronized void removeUser(String userID) - { - if (users.remove(userID) != null) - { - save(users); - } - } - - public byte[] encrypt(String userID, byte[] data, String algorithmName) throws SecurityException - { - char[] password; - synchronized (this) - { - password = users.get(userID); - } - - if (password == null) - { - throw new SecurityException("No such user: " + userID); - } - - try - { - return SecurityUtil.encrypt(data, password, algorithmName); - } - catch (RuntimeException ex) - { - throw ex; - } - catch (Exception ex) - { - throw new SecurityException(ex); - } - } - - @Override - protected void doActivate() throws Exception - { - super.doActivate(); - load(users); - } - - @Override - protected void doDeactivate() throws Exception - { - users.clear(); - super.doDeactivate(); - } - - protected void load(Map<String, char[]> users) throws IORuntimeException - { - } - - protected void save(Map<String, char[]> users) throws IORuntimeException - { - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerFactory.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerFactory.java deleted file mode 100644 index 448a721e63..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.security; - -import org.eclipse.net4j.internal.util.factory.Factory; - -/** - * @author Eike Stepper - */ -public abstract class UserManagerFactory extends Factory -{ - public static final String PRODUCT_GROUP = "org.eclipse.net4j.userManagers"; - - public UserManagerFactory(String type) - { - super(PRODUCT_GROUP, type); - } -} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/transaction/Transaction.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/transaction/Transaction.java deleted file mode 100644 index d96fe298cb..0000000000 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/transaction/Transaction.java +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Eike Stepper - initial API and implementation - **************************************************************************/ -package org.eclipse.net4j.internal.util.transaction; - -import org.eclipse.net4j.util.transaction.ITransaction; -import org.eclipse.net4j.util.transaction.ITransactionalOperation; -import org.eclipse.net4j.util.transaction.TransactionException; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class Transaction<CONTEXT> implements ITransaction<CONTEXT> -{ - private List<ITransactionalOperation<CONTEXT>> operations = new ArrayList<ITransactionalOperation<CONTEXT>>(); - - private CONTEXT context; - - private boolean undoPhase1OnRollback; - - public Transaction(CONTEXT context, boolean undoPhase1OnRollback) - { - this.context = context; - this.undoPhase1OnRollback = undoPhase1OnRollback; - } - - public Transaction(CONTEXT context) - { - this(context, true); - } - - public boolean isUndoPhase1OnRollback() - { - return undoPhase1OnRollback; - } - - public boolean isActive() - { - return operations != null; - } - - public CONTEXT getContext() - { - return context; - } - - public void execute(ITransactionalOperation<CONTEXT> operation) throws TransactionException - { - if (!isActive()) - { - throw new TransactionException("Transaction inactive"); - } - - try - { - operation.phase1(context); - operations.add(operation); - } - catch (RuntimeException ex) - { - rollback(); - throw ex; - } - catch (Exception ex) - { - rollback(); - throw new TransactionException(ex); - } - } - - public void commit() - { - for (ITransactionalOperation<CONTEXT> operation : end()) - { - operation.phase2(context); - } - } - - public void rollback() - { - if (undoPhase1OnRollback) - { - for (ITransactionalOperation<CONTEXT> operation : end()) - { - operation.undoPhase1(context); - } - } - } - - private List<ITransactionalOperation<CONTEXT>> end() - { - List<ITransactionalOperation<CONTEXT>> tmp = operations; - operations = null; - return tmp; - } -} |