Author: david.lloyd(a)jboss.com
Date: 2008-10-22 21:11:53 -0400 (Wed, 22 Oct 2008)
New Revision: 4615
Removed:
remoting3/trunk/api/src/main/java/org/jboss/remoting/CommonKeys.java
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/beans/
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaData.java
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaDataAttribute.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AtomicStateMachine.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeHashMap.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeKey.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeMap.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64DecodingException.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64Util.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/DelegateIterable.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/State.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/StateLock.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Translator.java
Modified:
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/RemotingMetaData.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
Log:
Yet more cleanup
Deleted: remoting3/trunk/api/src/main/java/org/jboss/remoting/CommonKeys.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/CommonKeys.java 2008-10-23
00:50:37 UTC (rev 4614)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/CommonKeys.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,60 +0,0 @@
-package org.jboss.remoting;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.jboss.remoting.util.AttributeKey;
-import static org.jboss.remoting.util.AttributeKey.key;
-
-import javax.security.auth.callback.CallbackHandler;
-
-/**
- * A set of attribute keys that are common across various protocols.
- */
-public final class CommonKeys {
- private CommonKeys() { /* no construction */ }
-
- // SASL
-
- /**
- * A key that represents the SASL properties to be used for this connection or
server.
- */
- public static final AttributeKey<Map<String, ?>> SASL_PROPERTIES =
key("SASL_PROPERTIES");
- /**
- * The SASL client mechanisms to try, in order. If none are given, then the list is
generated based on the registered
- * providers.
- */
- public static final AttributeKey<List<String>> SASL_CLIENT_MECHANISMS =
key("SASL_CLIENT_MECHANISMS");
- /**
- * The SASL server mechanisms to make available to clients. If none are given, then
the set is generated based on
- * the registered providers.
- */
- public static final AttributeKey<Set<String>> SASL_SERVER_MECHANISMS =
key("SASL_SERVER_MECHANISMS");
-
- // Generic auth
-
- /**
- * The authentication callback handler to make available to the authentication
layer.
- */
- public static final AttributeKey<CallbackHandler> AUTH_CALLBACK_HANDLER =
key("AUTH_CALLBACK_HANDLER");
- /**
- * The client authorization ID to send to the server. If not specified, defaults to
the local endpoint name. If
- * the local endpoint is anonymous, defaults to {@code null}.
- */
- public static final AttributeKey<String> AUTHORIZATION_ID =
key("AUTHORIZATION_ID");
- /**
- * The maximum number of times to retry authentication before giving up and failing.
- */
- public static final AttributeKey<Integer> AUTH_MAX_RETRIES =
key("AUTH_MAX_RETRIES");
-
- // TODO: add keys for SSL/TLS
-
- // Protocol keys
-
- /**
- * The keepalive interval. For protocols that are represented by a connection of
some sort, this property indicates
- * that a "keepalive" message should be sent at regular intervals to
prevent an idle connection from being
- * automatically closed by a firewall (for example).
- */
- public static final AttributeKey<Integer> KEEPALIVE_INTERVAL =
key("KEEPALIVE_INTERVAL");
-}
Modified:
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/RemotingMetaData.java
===================================================================
---
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/RemotingMetaData.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/RemotingMetaData.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -26,7 +26,6 @@
private static final long serialVersionUID = 1L;
private List<EndpointMetaData> endpoints;
- private List<SessionMetaData> sessions;
/**
* Get the list of nested endpoints as metadata.
@@ -48,25 +47,6 @@
}
/**
- * Get the list of nested sessions as metadata.
- *
- * @return the session metadata list
- */
- public List<SessionMetaData> getSessions() {
- return sessions;
- }
-
- /**
- * Set the list of nested sessions as metadata.
- *
- * @param sessions the session metadata list
- */
- @XmlElement(name = "session")
- public void setSessions(final List<SessionMetaData> sessions) {
- this.sessions = sessions;
- }
-
- /**
* Create a duplicate of this object.
*
* @return a duplicate of this object
@@ -77,9 +57,6 @@
for (EndpointMetaData endpointMetaData : endpoints) {
metaData.endpoints.add(endpointMetaData.clone());
}
- for (SessionMetaData sessionMetaData : sessions) {
- metaData.sessions.add(sessionMetaData.clone());
- }
return metaData;
}
@@ -94,9 +71,6 @@
for (EndpointMetaData endpointMetaData : endpoints) {
metaDataList.addAll(endpointMetaData.getBeans());
}
- for (SessionMetaData sessionMetaData : sessions) {
- metaDataList.addAll(sessionMetaData.getBeans());
- }
return Collections.unmodifiableList(metaDataList);
}
}
Deleted:
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaData.java
===================================================================
---
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaData.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaData.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,105 +0,0 @@
-package org.jboss.remoting.metadata;
-
-import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.remoting.util.AttributeMap;
-import org.jboss.remoting.util.AttributeHashMap;
-import org.jboss.remoting.util.AttributeKey;
-import org.jboss.remoting.util.CollectionUtil;
-import org.jboss.remoting.CommonKeys;
-import java.io.Serializable;
-import java.util.List;
-import java.net.URI;
-import java.lang.reflect.Field;
-
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-/**
- * Metadata which describes a session to be established and maintained with another
endpoint.
- */
-@XmlType(namespace = "urn:jboss:remoting:3.0", name = "session")
-public class SessionMetaData implements BeanMetaDataFactory, Serializable {
- private static final long serialVersionUID = 1L;
-
- private String name;
- private String endpoint;
- private URI destination;
- private List<SessionMetaDataAttribute> attributeList;
-
- public String getName() {
- return name;
- }
-
- @XmlAttribute(required = true)
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getEndpoint() {
- return endpoint;
- }
-
- @XmlAttribute(required = true)
- public void setEndpoint(final String endpoint) {
- this.endpoint = endpoint;
- }
-
- public URI getDestination() {
- return destination;
- }
-
- @XmlAttribute(required = true)
- public void setDestination(final URI destination) {
- this.destination = destination;
- }
-
- public List<SessionMetaDataAttribute> getAttributeList() {
- return attributeList;
- }
-
- @XmlElement(name = "attribute")
- public void setAttributeList(final List<SessionMetaDataAttribute>
attributeList) {
- this.attributeList = attributeList;
- }
-
- public SessionMetaData clone() throws CloneNotSupportedException {
- return (SessionMetaData) super.clone();
- }
-
- @XmlTransient
- public List<BeanMetaData> getBeans() {
- return CollectionUtil.unmodifiableList(createSessionMetaData());
- }
-
- @SuppressWarnings({"unchecked"})
- private static <T> void putAttribute(AttributeMap attributeMap,
AttributeKey<T> key, Object value) {
- attributeMap.put(key, (T) value);
- }
-
- private BeanMetaData createSessionMetaData() {
- final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name);
- builder.addPropertyMetaData("endpoint",
builder.createInject(endpoint));
- builder.addPropertyMetaData("destination", destination);
- final AttributeMap attributeMap = new AttributeHashMap();
- try {
- for (SessionMetaDataAttribute attribute : attributeList) {
- Class<?> claxx = Class.forName(attribute.getClaxx());
- if (claxx == null) {
- claxx = CommonKeys.class;
- }
- final String fieldName = attribute.getName();
- final Field field = claxx.getDeclaredField(fieldName);
- final AttributeKey<?> keyInstance = (AttributeKey<?>)
field.get(null);
- putAttribute(attributeMap, keyInstance, attribute.getValue());
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("Error reading field", e);
- }
- builder.addPropertyMetaData("attributeMap", attributeMap);
- return builder.getBeanMetaData();
- }
-}
Deleted:
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaDataAttribute.java
===================================================================
---
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaDataAttribute.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/mc-deployers/src/main/java/org/jboss/remoting/metadata/SessionMetaDataAttribute.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,42 +0,0 @@
-package org.jboss.remoting.metadata;
-
-import javax.xml.bind.annotation.XmlAnyElement;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- *
- */
-@XmlType(namespace = "urn:jboss:remoting:3.0", name = "attribute")
-public class SessionMetaDataAttribute {
- private String claxx;
- private String name;
- private Object value;
-
- public String getClaxx() {
- return claxx;
- }
-
- @XmlAttribute(name = "class")
- public void setClaxx(final String claxx) {
- this.claxx = claxx;
- }
-
- public String getName() {
- return name;
- }
-
- @XmlAttribute(name = "name", required = true)
- public void setName(final String name) {
- this.name = name;
- }
-
- public Object getValue() {
- return value;
- }
-
- @XmlAnyElement
- public void setValue(final Object value) {
- this.value = value;
- }
-}
Deleted:
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AtomicStateMachine.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AtomicStateMachine.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AtomicStateMachine.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,371 +0,0 @@
-package org.jboss.remoting.util;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- *
- */
-public final class AtomicStateMachine<T extends Enum<T> & State<T>>
{
- // protected by {@code lock}
- private T state;
-
- private final StateLock stateLock = new StateLock();
-
- public static <T extends Enum<T> & State<T>>
AtomicStateMachine<T> start(final T initialState) {
- return new AtomicStateMachine<T>(initialState);
- }
-
- private AtomicStateMachine(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- this.state = state;
- }
-
- public boolean transition(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockExclusive();
- try {
- if (this.state == state) {
- return false;
- }
- this.state = state;
- return true;
- } finally {
- stateLock.unlockExclusive();
- }
- }
-
- /**
- * Transition the state, and hold it at the given state until {@link #release()} is
called. Must not be
- * called if the state is already held from this thread.
- *
- * Example:
- * <pre>
- * if (state.transitionHold(State.STOPPING)) try {
- * // do stuff
- * } finally {
- * state.release();
- * }
- * </pre>
- *
- * @param state the target state
- * @return {@code true} if the transition happened
- */
- public boolean transitionHold(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockExclusive();
- try {
- if (this.state == state) {
- return false;
- }
- this.state = state;
- stateLock.lockShared();
- return true;
- } finally {
- stateLock.unlockExclusive();
- }
- }
-
- public boolean transitionExclusive(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockExclusive();
- if (this.state == state) {
- return false;
- }
- this.state = state;
- return true;
- }
-
- /**
- * Release a held state. Must be called from the same thread that is holding the
state.
- */
- public void release() {
- stateLock.unlockShared();
- }
-
- public void releaseExclusive() {
- stateLock.unlockExclusive();
- }
-
- public void releaseDowngrade() {
- stateLock.lockShared();
- stateLock.unlockExclusive();
- }
-
- public boolean transition(final T fromState, final T toState) {
- if (fromState == null) {
- throw new NullPointerException("fromState is null");
- }
- if (toState == null) {
- throw new NullPointerException("toState is null");
- }
- stateLock.lockExclusive();
- try {
- if (state != fromState) {
- return false;
- }
- state = toState;
- return true;
- } finally {
- stateLock.unlockExclusive();
- }
- }
-
- public boolean transitionHold(final T fromState, final T toState) {
- if (fromState == null) {
- throw new NullPointerException("fromState is null");
- }
- if (toState == null) {
- throw new NullPointerException("toState is null");
- }
- stateLock.lockExclusive();
- try {
- if (state != fromState) {
- return false;
- }
- state = toState;
- stateLock.lockShared();
- return true;
- } finally {
- stateLock.unlockExclusive();
- }
- }
-
- public boolean transitionExclusive(final T fromState, final T toState) {
- if (fromState == null) {
- throw new NullPointerException("fromState is null");
- }
- if (toState == null) {
- throw new NullPointerException("toState is null");
- }
- stateLock.lockExclusive();
- boolean ok = false;
- try {
- if (state != fromState) {
- return false;
- }
- state = toState;
- ok = true;
- return true;
- } finally {
- if (! ok) {
- stateLock.unlockExclusive();
- }
- }
- }
-
- public void requireTransition(final T state) {
- if (! transition(state)) {
- throw new IllegalStateException("Already in state " + state);
- }
- }
-
- public void requireTransitionHold(final T state) {
- if (! transitionHold(state)) {
- throw new IllegalStateException("Already in state " + state);
- }
- }
-
- public void requireTransition(final T fromState, final T toState) {
- if (! transition(fromState, toState)) {
- throw new IllegalStateException("Cannot transition from " +
fromState + " to " + toState + " (current state is " + state +
")");
- }
- }
-
- public void requireTransitionHold(final T fromState, final T toState) {
- if (! transitionHold(fromState, toState)) {
- throw new IllegalStateException("Cannot transition from " +
fromState + " to " + toState + " (current state is " + state +
")");
- }
- }
-
- public void requireTransitionExclusive(T fromState, T toState) {
- if (! transitionExclusive(fromState, toState)) {
- throw new IllegalStateException("Cannot transition from " +
fromState + " to " + toState + " (current state is " + state +
")");
- }
- }
-
- public void waitInterruptiblyFor(final T state) throws InterruptedException {
- stateLock.lockShared();
- while (this.state != state) {
- if (this.state.isReachable(state)) {
- stateLock.yieldShared();
- } else try {
- throw new IllegalStateException("Destination state " + state +
" is unreachable from " + this.state);
- } finally {
- stateLock.unlockShared();
- }
- }
- stateLock.unlockShared();
- return;
- }
-
- public void waitFor(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockShared();
- while (this.state != state) {
- if (this.state.isReachable(state)) {
- stateLock.yieldShared();
- } else try {
- throw new IllegalStateException("Destination state " + state +
" is unreachable from " + this.state);
- } finally {
- stateLock.unlockShared();
- }
- }
- stateLock.unlockShared();
- return;
- }
-
- public void waitForHold(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockShared();
- while (this.state != state) {
- if (this.state.isReachable(state)) {
- stateLock.yieldShared();
- } else try {
- throw new IllegalStateException("Destination state " + state +
" is unreachable from " + this.state);
- } finally {
- stateLock.unlockShared();
- }
- }
- return;
- }
-
- public T waitInterruptiblyForNotHold(final T state) throws InterruptedException {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockShared();
- while (this.state == state) {
- stateLock.yieldShared();
- }
- return this.state;
- }
-
- public T waitForNot(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockShared();
- while (this.state == state) {
- stateLock.yieldShared();
- }
- try {
- return this.state;
- } finally {
- stateLock.unlockShared();
- }
- }
-
- public T waitForNotHold(final T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- stateLock.lockShared();
- while (this.state == state) {
- stateLock.yieldShared();
- }
- return this.state;
- }
-
- public T waitInterruptiblyForNotHold(final T state, final long timeout, final
TimeUnit timeUnit) throws InterruptedException {
- throw new RuntimeException("TODO - Implement");
- }
-
- public T waitForNotHold(final T state, final long timeout, final TimeUnit timeUnit)
{
- throw new RuntimeException("TODO - Implement");
- }
-
- public T getState() {
- stateLock.lockShared();
- try {
- return state;
- } finally {
- stateLock.unlockShared();
- }
- }
-
- public T getStateHold() {
- stateLock.lockShared();
- return state;
- }
-
- public T getStateExclusive() {
- stateLock.lockExclusive();
- return state;
- }
-
- public boolean inHold(T state) {
- stateLock.lockShared();
- boolean ok = false;
- try {
- ok = this.state == state;
- return ok;
- } finally {
- if (! ok) {
- stateLock.unlockShared();
- }
- }
- }
-
- public boolean in(T state) {
- stateLock.lockShared();
- try {
- return this.state == state;
- } finally {
- stateLock.unlockShared();
- }
- }
-
- public boolean in(T... states) {
- if (states == null) {
- throw new NullPointerException("states is null");
- }
- stateLock.lockShared();
- try {
- for (T state : states) {
- if (this.state == state) {
- return true;
- }
- }
- return false;
- } finally {
- stateLock.unlockShared();
- }
- }
-
- public void requireHold(T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- boolean ok = false;
- stateLock.lockShared();
- try {
- if (this.state != state) {
- throw new IllegalStateException("Invalid state (expected " +
state + ", but current state is " + this.state + ")");
- }
- ok = true;
- } finally {
- if (! ok) stateLock.unlockShared();
- }
- }
-
- public String toString() {
- stateLock.lockShared();
- try {
- return "State = " + state;
- } finally {
- stateLock.unlockShared();
- }
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeHashMap.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeHashMap.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeHashMap.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,105 +0,0 @@
-package org.jboss.remoting.util;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- *
- */
-public final class AttributeHashMap implements AttributeMap {
- private final ConcurrentMap<AttributeKey<?>, Object> map =
CollectionUtil.concurrentMap();
-
- @SuppressWarnings ({"unchecked"})
- public <T> T get(AttributeKey<T> key) {
- return (T) map.get(key);
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T> T put(AttributeKey<T> key, T value) {
- return (T) map.put(key, value);
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T> T remove(AttributeKey<T> key) {
- return (T) map.remove(key);
- }
-
- public <T> boolean remove(AttributeKey<T> key, T value) {
- return map.remove(key, value);
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T> T putIfAbsent(AttributeKey<T> key, T value) {
- return (T) map.putIfAbsent(key, value);
- }
-
- public <T> boolean replace(AttributeKey<T> key, T oldValue, T newValue)
{
- return map.replace(key, oldValue, newValue);
- }
-
- public <T> boolean containsKey(AttributeKey<T> key) {
- return map.containsKey(key);
- }
-
- public <T> boolean containsValue(T value) {
- return map.containsValue(value);
- }
-
- public Iterable<Entry<?>> entries() {
- return new Iterable<Entry<?>>() {
- public Iterator<Entry<?>> iterator() {
- final Iterator<Map.Entry<AttributeKey<?>, Object>> i =
map.entrySet().iterator();
- return new Iterator<Entry<?>>() {
- public boolean hasNext() {
- return i.hasNext();
- }
-
- public Entry<?> next() {
- final Map.Entry<AttributeKey<?>, Object> ie =
i.next();
- return new Entry<Object>() {
- @SuppressWarnings ({"unchecked"})
- public AttributeKey<Object> getKey() {
- return (AttributeKey<Object>) ie.getKey();
- }
-
- public Object getValue() {
- return ie.getValue();
- }
-
- public void setValue(final Object newValue) {
- ie.setValue(newValue);
- }
- };
- }
-
- public void remove() {
- i.remove();
- }
- };
- }
- };
- }
-
- public Set<AttributeKey<?>> keySet() {
- return map.keySet();
- }
-
- public Collection<?> values() {
- return map.values();
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- public int size() {
- return map.size();
- }
-
- public void clear() {
- map.clear();
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeKey.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeKey.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeKey.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,20 +0,0 @@
-package org.jboss.remoting.util;
-
-/**
- *
- */
-public final class AttributeKey<T> {
- private final String name;
-
- public static <T> AttributeKey<T> key(String name) {
- return new AttributeKey<T>(name);
- }
-
- public AttributeKey(final String name) {
- this.name = name;
- }
-
- public String toString() {
- return "Key \"" + name + "\"";
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeMap.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeMap.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/AttributeMap.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,150 +0,0 @@
-package org.jboss.remoting.util;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * A map whose value types are determined by the key.
- */
-public interface AttributeMap {
-
- /**
- * The empty attribute map.
- */
- AttributeMap EMPTY = CollectionUtil.emptyAttributeMap();
-
- /**
- * Get a value from the map.
- *
- * @param key the key
- * @return the value
- */
- <T> T get(AttributeKey<T> key);
-
- /**
- * Store a value into the map. Any previous mapping for this value is overwritten.
- *
- * @param key the key
- * @param value the new value
- * @return the old value (may be {@code null}), or {@code null} if there was no
mapping for this key
- */
- <T> T put(AttributeKey<T> key, T value);
-
- /**
- * Remove a mapping from the map.
- *
- * @param key the key
- * @return the old value (may be {@code null}), or {@code null} if there was no
mapping for this key
- */
- <T> T remove(AttributeKey<T> key);
-
- /**
- * Remove a mapping from the map. Both the key and value must match the values
given.
- *
- * @param key the key
- * @param value the value
- * @return {@code true} if a matching mapping was located and removed
- */
- <T> boolean remove(AttributeKey<T> key, T value);
-
- /**
- * Store a value into the map if there is no value currently stored.
- *
- * @param key the key
- * @param value the value
- * @return the old value if there was a previous mapping
- */
- <T> T putIfAbsent(AttributeKey<T> key, T value);
-
- /**
- * Replace a mapping in the map.
- *
- * @param key the key
- * @param oldValue the old value
- * @param newValue the replacement value
- * @return {@code true} if a matching mapping was located and replaced
- */
- <T> boolean replace(AttributeKey<T> key, T oldValue, T newValue);
-
- /**
- * Test the map for the presence of a key.
- *
- * @param key the key
- * @return {@code true} if the key is present in the map
- */
- <T> boolean containsKey(AttributeKey<T> key);
-
- /**
- * Test the map for the presence of a value.
- *
- * @param value the value
- * @return {@code true} if the value is present in the map
- */
- <T> boolean containsValue(T value);
-
- /**
- * Get all the map entries.
- *
- * @return the entries
- */
- Iterable<Entry<?>> entries();
-
- /**
- * Get the key set for this map. The returned set supports all set operations except
for {@code add} and {@code addAll}.
- *
- * @return the key set
- */
- Set<AttributeKey<?>> keySet();
-
- /**
- * Get the collection of values for this map.
- *
- * @return the values
- */
- Collection<?> values();
-
- /**
- * Determine whether this map is empty.
- *
- * @return {@code true} if the map has no mappings
- */
- boolean isEmpty();
-
- /**
- * Determine the number of entries in the map.
- *
- * @return the number of entries
- */
- int size();
-
- /**
- * Clear the map of all mappings.
- */
- void clear();
-
- /**
- * An entry in the {@code AttributeMap}.
- */
- interface Entry<T> {
- /**
- * Get the entry key.
- *
- * @return the key
- */
- AttributeKey<T> getKey();
-
- /**
- * Get the entry value.
- *
- * @return the value
- */
- T getValue();
-
- /**
- * Change the entry value.
- *
- * @param newValue the new value
- */
- void setValue(T newValue);
- }
-}
Deleted:
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64DecodingException.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64DecodingException.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64DecodingException.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,21 +0,0 @@
-package org.jboss.remoting.util;
-
-/**
- *
- */
-public final class Base64DecodingException extends Exception {
- public Base64DecodingException() {
- }
-
- public Base64DecodingException(String message) {
- super(message);
- }
-
- public Base64DecodingException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public Base64DecodingException(Throwable cause) {
- super(cause);
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64Util.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64Util.java 2008-10-23
00:50:37 UTC (rev 4614)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Base64Util.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,151 +0,0 @@
-package org.jboss.remoting.util;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-
-/**
- *
- */
-public final class Base64Util {
-
- private Base64Util() {
- }
-
- /**
- * Base-64 decode a character buffer into a byte buffer.
- *
- * @param source the base-64 encoded source material
- * @param target the target for the decoded data
- * @throws Base64DecodingException if the source data is not in base-64 format
- */
- public static void base64Decode(CharBuffer source, ByteBuffer target) throws
Base64DecodingException {
- int triad;
- while (source.hasRemaining()) {
- triad = 0;
- char ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 18;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 18;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 18;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 18;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 18;
- } else if (ch == '=') {
- throw new Base64DecodingException("Unexpected padding
encountered");
- }
- if (! source.hasRemaining()) {
- throw new Base64DecodingException("Unexpected end of source
data");
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 12;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 12;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 12;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 12;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 12;
- } else if (ch == '=') {
- throw new Base64DecodingException("Unexpected padding
encountered");
- }
- if (! source.hasRemaining()) {
- throw new Base64DecodingException("Unexpected end of source
data");
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= (ch - 'A') << 6;
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= (ch - 'a' + 26) << 6;
- } else if (ch >= '0' && ch <= '9') {
- triad |= (ch - '0' + 52) << 6;
- } else if (ch == '+' || ch == '-') {
- triad |= 62 << 6;
- } else if (ch == '/' || ch == '_') {
- triad |= 63 << 6;
- } else if (ch == '=') {
- if (source.hasRemaining() && source.get() == '=') {
- if (! source.hasRemaining()) {
- target.put((byte) (triad >> 16));
- return;
- } else {
- throw new Base64DecodingException("Extra data after
padding");
- }
- } else {
- throw new Base64DecodingException("Unexpected end of source
data");
- }
- }
-
- ch = source.get();
- if (ch >= 'A' && ch <= 'Z') {
- triad |= ch - 'A';
- } else if (ch >= 'a' && ch <= 'z') {
- triad |= ch - 'a' + 26;
- } else if (ch >= '0' && ch <= '9') {
- triad |= ch - '0' + 52;
- } else if (ch == '+' || ch == '-') {
- triad |= 62;
- } else if (ch == '/' || ch == '_') {
- triad |= 63;
- } else if (ch == '=') {
- if (! source.hasRemaining()) {
- target.putShort((short) (triad >> 8));
- return;
- } else {
- throw new Base64DecodingException("Extra data after
padding");
- }
- }
-
- target.put((byte) (triad >> 16));
- target.putShort((short) triad);
- }
- }
-
- private static final char[] base64table = new char[] {
- 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H',
- 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X',
- 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't',
'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1',
'2', '3',
- '4', '5', '6', '7', '8', '9',
'+', '/',
- };
-
- /**
- * Base-64 encode a byte buffer into a character buffer.
- *
- * @param source the binary data to encode
- * @param target the target for the encoded material
- */
- public static void base64Encode(ByteBuffer source, CharBuffer target) {
- int idx = 0;
- while (source.hasRemaining()) {
- int b = source.get() & 0xff;
- target.put(base64table[b >>> 2]);
- idx = b << 4 & 0x3f;
- if (! source.hasRemaining()) {
- target.put(base64table[idx]);
- target.put("==");
- return;
- }
- b = source.get() & 0xff;
- target.put(base64table[idx | (b >>> 4)]);
- idx = b << 2 & 0x3f;
- if (! source.hasRemaining()) {
- target.put(base64table[idx]);
- target.put('=');
- return;
- }
- b = source.get() & 0xff;
- target.put(base64table[idx | (b >>> 6)]);
- target.put(base64table[b & 0x3f]);
- }
- }
-}
Modified: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -3,7 +3,6 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Enumeration;
@@ -345,78 +344,6 @@
}
/**
- * Run a translation function for each element of an {@code Enumeration}.
- *
- * @param input the input data
- * @param translator the translator
- * @return the translated data
- */
- public static <I,O> Enumeration<O> translate(final Enumeration<I>
input, final Translator<I, O> translator) {
- return new Enumeration<O>() {
- public boolean hasMoreElements() {
- return input.hasMoreElements();
- }
-
- public O nextElement() {
- return translator.translate(input.nextElement());
- }
- };
- }
-
- /**
- * Run a translation function for each element of an {@code Iterator}.
- *
- * @param input the input data
- * @param translator the translator
- * @return the translated data
- */
- public static <I,O> Iterator<O> translate(final Iterator<I> input,
final Translator<I, O> translator) {
- return new Iterator<O>() {
- public boolean hasNext() {
- return input.hasNext();
- }
-
- public O next() {
- return translator.translate(input.next());
- }
-
- public void remove() {
- input.remove();
- }
- };
- }
-
- /**
- * Run a translation function for each element of an {@code Iterable}.
- *
- * @param input the input data
- * @param translator the translator
- * @return the translated data
- */
- public static <I,O> Iterable<O> translate(final Iterable<I> input,
final Translator<I, O> translator) {
- return new Iterable<O>() {
- public Iterator<O> iterator() {
- return translate(input.iterator(), translator);
- }
- };
- }
-
- /**
- * Run a translation function for each element of a {@code List}, returning an {@code
ArrayList}.
- *
- * @param input the input list
- * @param translator the translator
- * @return the translated data
- */
- public static <I,O> ArrayList<O> translate(final List<I> input,
final Translator<I, O> translator) {
- final ArrayList<O> output = new ArrayList<O>(input.size());
- for (I item : input) {
- output.add(translator.translate(item));
- }
- return output;
- }
-
- /**
* Create an iterable view of a string split by a given delimiter.
*
* @param delimiter the delimiter
@@ -556,71 +483,6 @@
return true;
}
- public static AttributeMap emptyAttributeMap() {
- return EMPTY_ATTRIBUTE_MAP;
- }
-
- private static final AttributeMap EMPTY_ATTRIBUTE_MAP = new EmptyAttributeMap();
-
- private static final class EmptyAttributeMap implements AttributeMap {
-
- public <T> T get(final AttributeKey<T> key) {
- return null;
- }
-
- public <T> T put(final AttributeKey<T> key, final T value) {
- throw new UnsupportedOperationException("put()");
- }
-
- public <T> T remove(final AttributeKey<T> key) {
- return null;
- }
-
- public <T> boolean remove(final AttributeKey<T> key, final T value)
{
- return false;
- }
-
- public <T> T putIfAbsent(final AttributeKey<T> key, final T value) {
- throw new UnsupportedOperationException("putIfAbsent()");
- }
-
- public <T> boolean replace(final AttributeKey<T> key, final T
oldValue, final T newValue) {
- return false;
- }
-
- public <T> boolean containsKey(final AttributeKey<T> key) {
- return false;
- }
-
- public <T> boolean containsValue(final T value) {
- return false;
- }
-
- public Iterable<Entry<?>> entries() {
- return emptyIterable();
- }
-
- public Set<AttributeKey<?>> keySet() {
- return Collections.emptySet();
- }
-
- public Collection<?> values() {
- return Collections.emptySet();
- }
-
- public boolean isEmpty() {
- return true;
- }
-
- public int size() {
- return 0;
- }
-
- public void clear() {
- // might as well let it succeed
- }
- }
-
/**
* Get the empty iterable.
*
@@ -853,4 +715,17 @@
public static <T> Iterable<T> combine(final Iterable<? extends T>
first, final Iterable<? extends T> second, final Iterable<? extends T> third,
final Iterable<? extends T> fourth) {
return combine(combine(first, second), combine(third, fourth));
}
+
+ private static final class DelegateIterable<T> implements Iterable<T> {
+
+ private final Iterable<T> delegate;
+
+ public DelegateIterable(final Iterable<T> delegate) {
+ this.delegate = delegate;
+ }
+
+ public Iterator<T> iterator() {
+ return delegate.iterator();
+ }
+ }
}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/DelegateIterable.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/DelegateIterable.java 2008-10-23
00:50:37 UTC (rev 4614)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/DelegateIterable.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,18 +0,0 @@
-package org.jboss.remoting.util;
-
-import java.util.Iterator;
-
-/**
- *
- */
-public final class DelegateIterable<T> implements Iterable<T> {
- private final Iterable<T> delegate;
-
- public DelegateIterable(final Iterable<T> delegate) {
- this.delegate = delegate;
- }
-
- public Iterator<T> iterator() {
- return delegate.iterator();
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/State.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/State.java 2008-10-23
00:50:37 UTC (rev 4614)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/State.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,8 +0,0 @@
-package org.jboss.remoting.util;
-
-/**
- *
- */
-public interface State<T extends Enum<T> & State<T>> {
- boolean isReachable(T dest);
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/StateLock.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/StateLock.java 2008-10-23
00:50:37 UTC (rev 4614)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/StateLock.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,263 +0,0 @@
-package org.jboss.remoting.util;
-
-/**
- * Lock rules:
- *
- * Shared acquire:
- * - Unlocked
- * or
- * - Shared-locked
- *
- * Exclusive acquire:
- * - Unlocked
- * or
- * - All previously waiting readers have had a chance to lock
- */
-public final class StateLock {
- private static final class ReaderToken {
- private int count;
-
- private ReaderToken(final int count) {
- this.count = count;
- }
- }
-
- private static final String LOCK_NOT_HELD = "Unlock when lock isn't
held";
-
- private final Object lock = new Object();
- /**
- * A counter for the readers that will be granted after the next exclusive lock is
released.
- *
- * @protectedby {@code lock}
- */
- private ReaderToken nextReaderToken = new ReaderToken(0);
- /**
- * A counter for the readers that must be granted before an exclusive lock can be
granted.
- *
- * @protectedby {@code lock}
- */
- private ReaderToken currentReaderToken = new ReaderToken(0);
-
- // @protectedby {@code lock} (writes only)
- private volatile int sharedHolderCount = 0;
- // @protectedby {@code lock} (writes only)
- private volatile boolean exclusive = false;
-
- // @protectedby {@code lock} (all accesses)
- private int serial = 0;
-
- private final ThreadLocal<LockState> localLockState = new
ThreadLocal<LockState>();
-
- private void incLocalExclCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null) {
- localLockState.set(new LockState(1, 0));
- } else {
- lockState.exclLevel++;
- }
- }
-
- private boolean decLocalExclCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null || lockState.exclLevel == 0) {
- throw new IllegalMonitorStateException(LOCK_NOT_HELD);
- }
- return --lockState.exclLevel == 0;
- }
-
- private int getLocalExclCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null) {
- return 0;
- } else {
- return lockState.exclLevel;
- }
- }
-
- private void incLocalShrdCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null) {
- localLockState.set(new LockState(0, 1));
- } else {
- lockState.shrdLevel++;
- }
- }
-
- private boolean decLocalShrdCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null || lockState.shrdLevel == 0) {
- throw new IllegalMonitorStateException(LOCK_NOT_HELD);
- }
- return --lockState.shrdLevel == 0;
- }
-
- private int getLocalShrdCount() {
- final LockState lockState = localLockState.get();
- if (lockState == null) {
- return 0;
- } else {
- return lockState.shrdLevel;
- }
- }
-
- public void lockExclusive() {
- if (getLocalExclCount() > 0) {
- incLocalExclCount();
- return;
- }
- if (getLocalShrdCount() > 0) {
- throw new IllegalMonitorStateException("Lock exclusive while shared lock
is held");
- }
- synchronized (lock) {
- boolean intr = false;
- try {
- while (exclusive || currentReaderToken.count > 0 || sharedHolderCount
> 0) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- exclusive = true;
- serial++;
- incLocalExclCount();
- return;
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
- }
-
- public void unlockExclusive() {
- if (! exclusive) {
- throw new IllegalMonitorStateException(LOCK_NOT_HELD);
- }
- if (decLocalExclCount()) {
- synchronized (lock) {
- exclusive = false;
- currentReaderToken = nextReaderToken;
- nextReaderToken = new ReaderToken(0);
- lock.notifyAll();
- }
- }
- }
-
- public void lockShared() {
- if (getLocalShrdCount() > 0) {
- incLocalShrdCount();
- return;
- }
- if (getLocalExclCount() > 0) {
- sharedHolderCount++;
- incLocalShrdCount();
- return;
- }
- synchronized (lock) {
- boolean intr = false;
- try {
- final ReaderToken token = currentReaderToken;
- if (exclusive) {
- token.count++;
- while (exclusive) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- token.count--;
- }
- sharedHolderCount++;
- incLocalShrdCount();
- return;
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
- }
-
- public void unlockShared() {
- if (decLocalShrdCount()) {
- synchronized (lock) {
- if (--sharedHolderCount == 0) {
- lock.notifyAll();
- }
- }
- }
- }
-
- public void yieldShared() {
- if (getLocalShrdCount() == 1 && getLocalExclCount() == 0) {
- synchronized (lock) {
- boolean intr = false;
- try {
- final ReaderToken token = nextReaderToken;
- token.count++;
- sharedHolderCount--;
- if (sharedHolderCount == 0) {
- lock.notifyAll();
- }
- final int origSerial = serial;
- while (serial == origSerial || exclusive) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- token.count--;
- sharedHolderCount++;
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
- } else {
- throw new IllegalMonitorStateException("May only hold one shared lock to
invoke yieldShared()");
- }
- }
-
- public void awaitExclusive() {
- if (getLocalExclCount() == 0) {
- throw new IllegalMonitorStateException("await() called when lock not
held");
- }
- synchronized (lock) {
- boolean intr = false;
- try {
- exclusive = false;
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- while (exclusive || currentReaderToken.count > 0 || sharedHolderCount
> 0) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- exclusive = true;
- incLocalExclCount();
- return;
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
- }
- }
-
- public void signal() {
- synchronized (lock) {
- lock.notifyAll();
- }
- }
-
- private static final class LockState {
- private int exclLevel;
- private int shrdLevel;
-
- private LockState(final int exclLevel, final int shrdLevel) {
- this.exclLevel = exclLevel;
- this.shrdLevel = shrdLevel;
- }
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Translator.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Translator.java 2008-10-23
00:50:37 UTC (rev 4614)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/Translator.java 2008-10-23
01:11:53 UTC (rev 4615)
@@ -1,8 +0,0 @@
-package org.jboss.remoting.util;
-
-/**
- *
- */
-public interface Translator<I, O> {
- O translate(I input);
-}