Apply patch (FELIX-2378) to avoid coarse-grained synchronization.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@950090 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell/src/main/java/org/apache/felix/shell/impl/Activator.java b/shell/src/main/java/org/apache/felix/shell/impl/Activator.java
index 567e7fa..d68ed0c 100644
--- a/shell/src/main/java/org/apache/felix/shell/impl/Activator.java
+++ b/shell/src/main/java/org/apache/felix/shell/impl/Activator.java
@@ -210,55 +210,70 @@
org.apache.felix.shell.ShellService,
org.ungoverned.osgi.service.shell.ShellService
{
- private HashMap m_commandRefMap = new HashMap();
- private TreeMap m_commandNameMap = new TreeMap();
+ private final HashMap m_commandRefMap = new HashMap();
+ private final TreeMap m_commandNameMap = new TreeMap();
- public synchronized String[] getCommands()
+ public String[] getCommands()
{
- Set ks = m_commandNameMap.keySet();
- String[] cmds = (ks == null)
- ? new String[0] : (String[]) ks.toArray(new String[ks.size()]);
- return cmds;
+ synchronized(m_commandRefMap)
+ {
+ Set ks = m_commandNameMap.keySet();
+ String[] cmds = (ks == null)
+ ? new String[0] : (String[]) ks.toArray(new String[ks.size()]);
+ return cmds;
+ }
}
- public synchronized String getCommandUsage(String name)
+ public String getCommandUsage(String name)
{
- Command command = (Command) m_commandNameMap.get(name);
- return (command == null) ? null : command.getUsage();
+ synchronized(m_commandRefMap)
+ {
+ Command command = (Command) m_commandNameMap.get(name);
+ return (command == null) ? null : command.getUsage();
+ }
}
- public synchronized String getCommandDescription(String name)
+ public String getCommandDescription(String name)
{
- Command command = (Command) m_commandNameMap.get(name);
- return (command == null) ? null : command.getShortDescription();
+ synchronized(m_commandRefMap)
+ {
+ Command command = (Command) m_commandNameMap.get(name);
+ return (command == null) ? null : command.getShortDescription();
+ }
}
- public synchronized ServiceReference getCommandReference(String name)
+ public ServiceReference getCommandReference(String name)
{
ServiceReference ref = null;
- Iterator itr = m_commandRefMap.entrySet().iterator();
- while (itr.hasNext())
+ synchronized(m_commandRefMap)
{
- Map.Entry entry = (Map.Entry) itr.next();
- if (((Command) entry.getValue()).getName().equals(name))
- {
- ref = (ServiceReference) entry.getKey();
- break;
- }
+ Iterator itr = m_commandRefMap.entrySet().iterator();
+ while (itr.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) itr.next();
+ if (((Command) entry.getValue()).getName().equals(name))
+ {
+ ref = (ServiceReference) entry.getKey();
+ break;
+ }
+ }
}
return ref;
}
- public synchronized void removeCommand(ServiceReference ref)
+ public void removeCommand(ServiceReference ref)
{
- Command command = (Command) m_commandRefMap.remove(ref);
- if (command != null)
+ synchronized(m_commandRefMap)
{
- m_commandNameMap.remove(command.getName());
- }
+ Command command = (Command) m_commandRefMap.remove(ref);
+ if (command != null)
+ {
+ m_commandNameMap.remove(command.getName());
+ }
+ }
}
- public synchronized void executeCommand(
+ public void executeCommand(
String commandLine, PrintStream out, PrintStream err) throws Exception
{
commandLine = commandLine.trim();
@@ -298,27 +313,36 @@
}
}
- protected synchronized Command getCommand(String name)
+ protected Command getCommand(String name)
{
- Command command = (Command) m_commandNameMap.get(name);
- return (command == null) ? null : command;
+ synchronized(m_commandRefMap)
+ {
+ Command command = (Command) m_commandNameMap.get(name);
+ return (command == null) ? null : command;
+ }
}
- protected synchronized void addCommand(ServiceReference ref)
+ protected void addCommand(ServiceReference ref)
{
Object cmdObj = m_context.getService(ref);
Command command =
(cmdObj instanceof org.ungoverned.osgi.service.shell.Command)
? new OldCommandWrapper((org.ungoverned.osgi.service.shell.Command) cmdObj)
: (Command) cmdObj;
- m_commandRefMap.put(ref, command);
- m_commandNameMap.put(command.getName(), command);
+ synchronized(m_commandRefMap)
+ {
+ m_commandRefMap.put(ref, command);
+ m_commandNameMap.put(command.getName(), command);
+ }
}
- protected synchronized void clearCommands()
+ protected void clearCommands()
{
- m_commandRefMap.clear();
- m_commandNameMap.clear();
+ synchronized(m_commandRefMap)
+ {
+ m_commandRefMap.clear();
+ m_commandNameMap.clear();
+ }
}
}