/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.naming.Binding;
import javax.naming.NamingException;
/**
* The context attributes for this context.
*/
- private HashMap attributes = new HashMap();
+ private Map attributes = new ConcurrentHashMap();
/**
* List of read only attributes for this context.
*/
- private HashMap readOnlyAttributes = new HashMap();
+ private Map readOnlyAttributes = new ConcurrentHashMap();
/**
/**
* The merged context initialization parameters for this Context.
*/
- private HashMap parameters = null;
+ private Map parameters = null;
/**
*/
public Object getAttribute(String name) {
- synchronized (attributes) {
- return (attributes.get(name));
- }
+ return (attributes.get(name));
}
*/
public Enumeration getAttributeNames() {
- synchronized (attributes) {
- return new Enumerator(attributes.keySet(), true);
- }
+ return new Enumerator(attributes.keySet(), true);
}
public String getInitParameter(final String name) {
mergeParameters();
- synchronized (parameters) {
- return ((String) parameters.get(name));
- }
+ return ((String) parameters.get(name));
+
}
public Enumeration getInitParameterNames() {
mergeParameters();
- synchronized (parameters) {
- return (new Enumerator(parameters.keySet()));
- }
+ return (new Enumerator(parameters.keySet()));
}
boolean found = false;
// Remove the specified attribute
- synchronized (attributes) {
- // Check for read only attribute
- if (readOnlyAttributes.containsKey(name))
- return;
- found = attributes.containsKey(name);
- if (found) {
- value = attributes.get(name);
- attributes.remove(name);
- } else {
- return;
- }
+ // Check for read only attribute
+ if (readOnlyAttributes.containsKey(name))
+ return;
+ found = attributes.containsKey(name);
+ if (found) {
+ value = attributes.get(name);
+ attributes.remove(name);
+ } else {
+ return;
}
// Notify interested application event listeners
boolean replaced = false;
// Add or replace the specified attribute
- synchronized (attributes) {
- // Check for read only attribute
- if (readOnlyAttributes.containsKey(name))
- return;
- oldValue = attributes.get(name);
- if (oldValue != null)
- replaced = true;
- attributes.put(name, value);
- }
+ // Check for read only attribute
+ if (readOnlyAttributes.containsKey(name))
+ return;
+ oldValue = attributes.get(name);
+ if (oldValue != null)
+ replaced = true;
+ attributes.put(name, value);
// Notify interested application event listeners
Object listeners[] = context.getApplicationEventListeners();
// Create list of attributes to be removed
ArrayList list = new ArrayList();
- synchronized (attributes) {
- Iterator iter = attributes.keySet().iterator();
- while (iter.hasNext()) {
- list.add(iter.next());
- }
+ Iterator iter = attributes.keySet().iterator();
+ while (iter.hasNext()) {
+ list.add(iter.next());
}
// Remove application originated attributes
*/
void setAttributeReadOnly(String name) {
- synchronized (attributes) {
- if (attributes.containsKey(name))
- readOnlyAttributes.put(name, name);
- }
+ if (attributes.containsKey(name))
+ readOnlyAttributes.put(name, name);
}
if (parameters != null)
return;
- HashMap results = new HashMap();
+ Map results = new ConcurrentHashMap();
String names[] = context.findParameters();
for (int i = 0; i < names.length; i++)
results.put(names[i], context.findParameter(names[i]));
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
* The set of currently active Sessions for this Manager, keyed by
* session identifier.
*/
- protected HashMap sessions = new HashMap();
+ protected Map sessions = new ConcurrentHashMap();
// Number of sessions created by this manager
protected int sessionCounter=0;
*/
public void add(Session session) {
- synchronized (sessions) {
- sessions.put(session.getIdInternal(), session);
- if( sessions.size() > maxActive ) {
- maxActive=sessions.size();
- }
+ sessions.put(session.getIdInternal(), session);
+ int size = sessions.size();
+ if( size > maxActive ) {
+ maxActive = size;
}
}
if (id == null)
return (null);
- synchronized (sessions) {
- Session session = (Session) sessions.get(id);
- return (session);
- }
+ return (Session) sessions.get(id);
}
*/
public void remove(Session session) {
- synchronized (sessions) {
- sessions.remove(session.getIdInternal());
- }
+ sessions.remove(session.getIdInternal());
}
*/
public String listSessionIds() {
StringBuffer sb=new StringBuffer();
- Iterator keys=sessions.keySet().iterator();
- while( keys.hasNext() ) {
+ Iterator keys = sessions.keySet().iterator();
+ while (keys.hasNext()) {
sb.append(keys.next()).append(" ");
}
return sb.toString();
* @return The attribute value, if found, null otherwise
*/
public String getSessionAttribute( String sessionId, String key ) {
- Session s=(Session)sessions.get(sessionId);
+ Session s = (Session) sessions.get(sessionId);
if( s==null ) {
if(log.isInfoEnabled())
log.info("Session not found " + sessionId);