You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/04/25 16:50:38 UTC

svn commit: r768539 - in /felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote: Activator.java AtomicInteger.java Latch.java Listener.java ReentrantLock.java ServiceMediator.java Shell.java TerminalPrintStream.java TerminalReader.java

Author: rickhall
Date: Sat Apr 25 14:50:37 2009
New Revision: 768539

URL: http://svn.apache.org/viewvc?rev=768539&view=rev
Log:
Reformatted code to Felix code style.

Modified:
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Activator.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/AtomicInteger.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Latch.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Listener.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ReentrantLock.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ServiceMediator.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java
    felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Activator.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Activator.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Activator.java Sat Apr 25 14:50:37 2009
@@ -1,71 +1,64 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
-
 /**
  * Activator for the telnet console.
  */
 public class Activator implements BundleActivator
 {
+    private static ServiceMediator c_services;
+    private Listener m_listener;
 
-    private static ServiceMediator c_Services;
-    private Listener m_Listener;
-
-
-    public void start( BundleContext bundleContext ) throws Exception
+    public void start(BundleContext bundleContext) throws Exception
     {
         //1. Prepare mediator
-        c_Services = new ServiceMediator();
-        c_Services.activate( bundleContext );
+        c_services = new ServiceMediator();
+        c_services.activate(bundleContext);
 
         //2. Prepare the listener
-        m_Listener = new Listener();
-        m_Listener.activate( bundleContext );
+        m_listener = new Listener();
+        m_listener.activate(bundleContext);
     }
 
-
-    public void stop( BundleContext bundleContext ) throws Exception
+    public void stop(BundleContext bundleContext) throws Exception
     {
-        if ( m_Listener != null )
+        if (m_listener != null)
         {
-            m_Listener.deactivate();
-            m_Listener = null;
+            m_listener.deactivate();
+            m_listener = null;
         }
-        if ( c_Services != null )
+        if (c_services != null)
         {
-            c_Services.deactivate();
-            c_Services = null;
+            c_services.deactivate();
+            c_services = null;
         }
     }
 
-
     /**
      * Returns a reference to the {@link ServiceMediator} instance used in this bundle.
      *
      * @return a {@link ServiceMediator} instance.
      */
-    public static ServiceMediator getServices()
+    static ServiceMediator getServices()
     {
-        return c_Services;
+        return c_services;
     }
-
-}
+}
\ No newline at end of file

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/AtomicInteger.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/AtomicInteger.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/AtomicInteger.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/AtomicInteger.java Sat Apr 25 14:50:37 2009
@@ -1,49 +1,44 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 /**
  * Provides an atomic integer.
  */
 class AtomicInteger
 {
-
-    private int m_Value;
-
+    private int m_value;
 
     public AtomicInteger()
     {
-        m_Value = 0;
+        m_value = 0;
     }//constructor
 
-
     /**
      * Constructs a new <tt>AtomicInteger</tt>
      * with a given initial value.
      *
      * @param value the initial value.
      */
-    public AtomicInteger( int value )
+    public AtomicInteger(int value)
     {
-        m_Value = value;
+        m_value = value;
     }//constructor
 
-
     /**
      * Increments this <tt>AtomicInteger</tt> by one.
      *
@@ -51,10 +46,9 @@
      */
     public synchronized int increment()
     {
-        return ++m_Value;
+        return ++m_value;
     }//increment
 
-
     /**
      * Decrements this <tt>AtomicInteger</tt> by one.
      *
@@ -62,21 +56,19 @@
      */
     public synchronized int decrement()
     {
-        return --m_Value;
+        return --m_value;
     }//decrement
 
-
     /**
      * Sets the value of this <tt>AtomicInteger</tt>.
      *
      * @param i the new value.
      */
-    public synchronized void set( int i )
+    public synchronized void set(int i)
     {
-        m_Value = i;
+        m_value = i;
     }//set
 
-
     /**
      * Returns the value of this <tt>AtomicInteger</tt>.
      *
@@ -84,7 +76,6 @@
      */
     public synchronized int get()
     {
-        return m_Value;
+        return m_value;
     }//get
-
 }//class AtomicInteger

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Latch.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Latch.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Latch.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Latch.java Sat Apr 25 14:50:37 2009
@@ -1,22 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 /**
  * A latch is a boolean condition that is set at most once, ever.
  * Once a single release is issued, all acquires will pass.
@@ -48,71 +47,78 @@
  */
 class Latch
 {
-
-    protected boolean latched_ = false;
-
+    private boolean m_latched = false;
 
     /*
-      This could use double-check, but doesn't.
-      If the latch is being used as an indicator of
-      the presence or state of an object, the user would
-      not necessarily get the memory barrier that comes with synch
-      that would be needed to correctly use that object. This
-      would lead to errors that users would be very hard to track down. So, to
-      be conservative, we always use synch.
-    */
-
+    This could use double-check, but doesn't.
+    If the latch is being used as an indicator of
+    the presence or state of an object, the user would
+    not necessarily get the memory barrier that comes with synch
+    that would be needed to correctly use that object. This
+    would lead to errors that users would be very hard to track down. So, to
+    be conservative, we always use synch.
+     */
     public void acquire() throws InterruptedException
     {
-        if ( Thread.interrupted() )
+        if (Thread.interrupted())
+        {
             throw new InterruptedException();
-        synchronized ( this )
+        }
+        synchronized (this)
         {
-            while ( !latched_ )
+            while (!m_latched)
+            {
                 wait();
+            }
         }
     }//acquire
 
-
-    public boolean attempt( long msecs ) throws InterruptedException
+    public boolean attempt(long msecs) throws InterruptedException
     {
-        if ( Thread.interrupted() )
+        if (Thread.interrupted())
+        {
             throw new InterruptedException();
-        synchronized ( this )
+        }
+        synchronized (this)
         {
-            if ( latched_ )
+            if (m_latched)
+            {
                 return true;
-            else if ( msecs <= 0 )
+            }
+            else if (msecs <= 0)
+            {
                 return false;
+            }
             else
             {
                 long waitTime = msecs;
                 long start = System.currentTimeMillis();
-                for ( ;; )
+                for (;;)
                 {
-                    wait( waitTime );
-                    if ( latched_ )
+                    wait(waitTime);
+                    if (m_latched)
+                    {
                         return true;
+                    }
                     else
                     {
-                        waitTime = msecs - ( System.currentTimeMillis() - start );
-                        if ( waitTime <= 0 )
+                        waitTime = msecs - (System.currentTimeMillis() - start);
+                        if (waitTime <= 0)
+                        {
                             return false;
+                        }
                     }
                 }
             }
         }
     }//attempt
 
-
     /**
      * Enable all current and future acquires to pass *
      */
     public synchronized void release()
     {
-        latched_ = true;
+        m_latched = true;
         notifyAll();
     }//release
-
-}//class Latch
-
+}//class Latch
\ No newline at end of file

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Listener.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Listener.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Listener.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Listener.java Sat Apr 25 14:50:37 2009
@@ -1,22 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import java.io.IOException;
 import java.io.PrintStream;
 import java.net.InetAddress;
@@ -29,41 +28,37 @@
 
 import org.osgi.framework.BundleContext;
 
-
 /**
  * Implements a simple listener that will accept a single connection.
  */
 class Listener
 {
-
-    private int m_Port;
-    private String m_Ip;
-    private Thread m_ListenerThread;
-    private boolean m_Stop = false;
-    private ServerSocket m_ServerSocket;
-    private AtomicInteger m_UseCounter;
-    private int m_MaxConnections;
-    private int m_SoTimeout;
+    private int m_port;
+    private String m_ip;
+    private Thread m_listenerThread;
+    private boolean m_stop = false;
+    private ServerSocket m_serverSocket;
+    private AtomicInteger m_useCounter;
+    private int m_maxConnections;
+    private int m_soTimeout;
     private Set m_connections;
 
-
     /**
      * Activates this listener on a listener thread (telnetconsole.Listener).
      */
-    public void activate( BundleContext bundleContext )
+    public void activate(BundleContext bundleContext)
     {
         //configure from framework property
-        m_Ip = getProperty( bundleContext, "osgi.shell.telnet.ip", "127.0.0.1" );
-        m_Port = getProperty( bundleContext, "osgi.shell.telnet.port", 6666 );
-        m_SoTimeout = getProperty( bundleContext, "osgi.shell.telnet.socketTimeout", 0 );
-        m_MaxConnections = getProperty( bundleContext, "osgi.shell.telnet.maxconn", 2 );
-        m_UseCounter = new AtomicInteger( 0 );
+        m_ip = getProperty(bundleContext, "osgi.shell.telnet.ip", "127.0.0.1");
+        m_port = getProperty(bundleContext, "osgi.shell.telnet.port", 6666);
+        m_soTimeout = getProperty(bundleContext, "osgi.shell.telnet.socketTimeout", 0);
+        m_maxConnections = getProperty(bundleContext, "osgi.shell.telnet.maxconn", 2);
+        m_useCounter = new AtomicInteger(0);
         m_connections = new HashSet();
-        m_ListenerThread = new Thread( new Acceptor(), "telnetconsole.Listener" );
-        m_ListenerThread.start();
+        m_listenerThread = new Thread(new Acceptor(), "telnetconsole.Listener");
+        m_listenerThread.start();
     }//activate
 
-
     /**
      * Deactivates this listener.
      * <p/>
@@ -75,29 +70,29 @@
     {
         try
         {
-            m_Stop = true;
+            m_stop = true;
             //wait for the listener thread
-            m_ServerSocket.close();
-            m_ListenerThread.join();
+            m_serverSocket.close();
+            m_listenerThread.join();
         }
-        catch ( Exception ex )
+        catch (Exception ex)
         {
-            Activator.getServices().error( "Listener::deactivate()", ex );
+            Activator.getServices().error("Listener::deactivate()", ex);
         }
-        
+
         // get the active connections (and clear the list)
         // we have to work on a copy, since stopping any active connection
         // will try to remove itself from the set, which might cause a
         // ConcurrentModificationException if we would iterate over the list
         Shell[] connections;
-        synchronized ( m_connections )
+        synchronized (m_connections)
         {
-            connections = ( Shell[] ) m_connections.toArray( new Shell[m_connections.size()] );
+            connections = (Shell[]) m_connections.toArray(new Shell[m_connections.size()]);
             m_connections.clear();
         }
 
         // now terminate all active connections
-        for ( int i = 0; i < connections.length; i++ )
+        for (int i = 0; i < connections.length; i++)
         {
             connections[i].terminate();
         }
@@ -108,7 +103,6 @@
      */
     private class Acceptor implements Runnable
     {
-
         /**
          * Listens constantly to a server socket and handles incoming connections.
          * One connection will be accepted and routed into the shell, all others will
@@ -123,23 +117,23 @@
             try
             {
                 /*
-                    A server socket is opened with a connectivity queue of a size specified
-                    in int floodProtection.  Concurrent login handling under normal circumstances
-                    should be handled properly, but denial of service attacks via massive parallel
-                    program logins should be prevented with this.
-                */
-                m_ServerSocket = new ServerSocket( m_Port, 1, InetAddress.getByName( m_Ip ) );
-                m_ServerSocket.setSoTimeout( m_SoTimeout );
+                A server socket is opened with a connectivity queue of a size specified
+                in int floodProtection.  Concurrent login handling under normal circumstances
+                should be handled properly, but denial of service attacks via massive parallel
+                program logins should be prevented with this.
+                 */
+                m_serverSocket = new ServerSocket(m_port, 1, InetAddress.getByName(m_ip));
+                m_serverSocket.setSoTimeout(m_soTimeout);
                 do
                 {
                     try
                     {
-                        Socket s = m_ServerSocket.accept();
-                        if ( m_UseCounter.get() >= m_MaxConnections )
+                        Socket s = m_serverSocket.accept();
+                        if (m_useCounter.get() >= m_maxConnections)
                         {
                             //reject with message
-                            PrintStream out = new PrintStream( s.getOutputStream() );
-                            out.print( INUSE_MESSAGE );
+                            PrintStream out = new PrintStream(s.getOutputStream());
+                            out.print(INUSE_MESSAGE);
                             out.flush();
                             //close
                             out.close();
@@ -147,57 +141,55 @@
                         }
                         else
                         {
-                            m_UseCounter.increment();
+                            m_useCounter.increment();
                             //run on the connection thread
-                            Thread connectionThread = new Thread( new Shell( Listener.this, s, m_UseCounter ) );
-                            connectionThread.setName( "telnetconsole.shell remote=" + s.getRemoteSocketAddress() );
+                            Thread connectionThread = new Thread(new Shell(Listener.this, s, m_useCounter));
+                            connectionThread.setName("telnetconsole.shell remote=" + s.getRemoteSocketAddress());
                             connectionThread.start();
                         }
                     }
-                    catch ( SocketException ex )
+                    catch (SocketException ex)
                     {
                     }
-                    catch ( SocketTimeoutException ste) {
+                    catch (SocketTimeoutException ste)
+                    {
                         // Caught socket timeout exception. continue
                     }
                 }
-                while ( !m_Stop );
+                while (!m_stop);
 
             }
-            catch ( IOException e )
+            catch (IOException e)
             {
-                Activator.getServices().error( "Listener.Acceptor::activate()", e );
+                Activator.getServices().error("Listener.Acceptor::activate()", e);
             }
         }//run
-
     }//inner class Acceptor
 
-    private static final String INUSE_MESSAGE = "Connection refused.\r\n"
-        + "All possible connections are currently being used.\r\n";
-
+    private static final String INUSE_MESSAGE = "Connection refused.\r\n" + "All possible connections are currently being used.\r\n";
 
-    private int getProperty( BundleContext bundleContext, String propName, int defaultValue )
+    private int getProperty(BundleContext bundleContext, String propName, int defaultValue)
     {
-        String propValue = bundleContext.getProperty( propName );
-        if ( propValue != null )
+        String propValue = bundleContext.getProperty(propName);
+        if (propValue != null)
         {
             try
             {
-                return Integer.parseInt( propValue );
+                return Integer.parseInt(propValue);
             }
-            catch ( NumberFormatException ex )
+            catch (NumberFormatException ex)
             {
-                Activator.getServices().error( "Listener::activate()", ex );
+                Activator.getServices().error("Listener::activate()", ex);
             }
         }
 
         return defaultValue;
     }
 
-    private String getProperty( BundleContext bundleContext, String propName, String defaultValue )
+    private String getProperty(BundleContext bundleContext, String propName, String defaultValue)
     {
-        String propValue = bundleContext.getProperty( propName );
-        if ( propValue != null )
+        String propValue = bundleContext.getProperty(propName);
+        if (propValue != null)
         {
             return propValue;
         }
@@ -216,11 +208,11 @@
      * 
      * @param connection The {@link Shell} connection to register
      */
-    void registerConnection( Shell connection )
+    void registerConnection(Shell connection)
     {
-        synchronized ( m_connections )
+        synchronized (m_connections)
         {
-            m_connections.add( connection );
+            m_connections.add(connection);
         }
     }
 
@@ -234,11 +226,11 @@
      * 
      * @param connection The {@link Shell} connection to unregister
      */
-    void unregisterConnection( Shell connection )
+    void unregisterConnection(Shell connection)
     {
-        synchronized ( m_connections )
+        synchronized (m_connections)
         {
-            m_connections.remove( connection );
+            m_connections.remove(connection);
         }
     }
 }//class Listener

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ReentrantLock.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ReentrantLock.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ReentrantLock.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ReentrantLock.java Sat Apr 25 14:50:37 2009
@@ -1,22 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 /**
  * Implements a reentrant lock.
  * <p/>
@@ -24,31 +23,35 @@
  */
 class ReentrantLock
 {
-
-    protected Thread m_Owner = null;
-    protected long m_Holds = 0;
-
+    protected Thread m_owner = null;
+    protected long m_holds = 0;
 
     public void acquire() throws InterruptedException
     {
         //log.debug("acquire()::" + Thread.currentThread().toString());
-        if ( Thread.interrupted() )
+        if (Thread.interrupted())
+        {
             throw new InterruptedException();
+        }
         Thread caller = Thread.currentThread();
-        synchronized ( this )
+        synchronized (this)
         {
-            if ( caller == m_Owner )
-                ++m_Holds;
+            if (caller == m_owner)
+            {
+                ++m_holds;
+            }
             else
             {
                 try
                 {
-                    while ( m_Owner != null )
+                    while (m_owner != null)
+                    {
                         wait();
-                    m_Owner = caller;
-                    m_Holds = 1;
+                    }
+                    m_owner = caller;
+                    m_holds = 1;
                 }
-                catch ( InterruptedException ex )
+                catch (InterruptedException ex)
                 {
                     notify();
                     throw ex;
@@ -57,57 +60,62 @@
         }
     }//acquire
 
-
-    public boolean attempt( long msecs ) throws InterruptedException
+    public boolean attempt(long msecs) throws InterruptedException
     {
         //log.debug("attempt()::" + Thread.currentThread().toString());
-        if ( Thread.interrupted() )
+        if (Thread.interrupted())
+        {
             throw new InterruptedException();
+        }
         Thread caller = Thread.currentThread();
-        synchronized ( this )
+        synchronized (this)
         {
-            if ( caller == m_Owner )
+            if (caller == m_owner)
             {
-                ++m_Holds;
+                ++m_holds;
                 return true;
             }
-            else if ( m_Owner == null )
+            else if (m_owner == null)
             {
-                m_Owner = caller;
-                m_Holds = 1;
+                m_owner = caller;
+                m_holds = 1;
                 return true;
             }
-            else if ( msecs <= 0 )
+            else if (msecs <= 0)
+            {
                 return false;
+            }
             else
             {
                 long waitTime = msecs;
                 long start = System.currentTimeMillis();
                 try
                 {
-                    for ( ;; )
+                    for (;;)
                     {
-                        wait( waitTime );
-                        if ( caller == m_Owner )
+                        wait(waitTime);
+                        if (caller == m_owner)
                         {
-                            ++m_Holds;
+                            ++m_holds;
                             return true;
                         }
-                        else if ( m_Owner == null )
+                        else if (m_owner == null)
                         {
-                            m_Owner = caller;
-                            m_Holds = 1;
+                            m_owner = caller;
+                            m_holds = 1;
                             return true;
                         }
                         else
                         {
-                            waitTime = msecs - ( System.currentTimeMillis() - start );
-                            if ( waitTime <= 0 )
+                            waitTime = msecs - (System.currentTimeMillis() - start);
+                            if (waitTime <= 0)
+                            {
                                 return false;
+                            }
                         }
                     }
                 }
-                catch ( InterruptedException ex )
+                catch (InterruptedException ex)
                 {
                     notify();
                     throw ex;
@@ -116,7 +124,6 @@
         }
     }//attempt
 
-
     /**
      * Release the lock.
      *
@@ -125,17 +132,18 @@
     public synchronized void release()
     {
         //log.debug("release()::" + Thread.currentThread().toString());
-        if ( Thread.currentThread() != m_Owner )
-            throw new Error( "Illegal Lock usage" );
+        if (Thread.currentThread() != m_owner)
+        {
+            throw new Error("Illegal Lock usage");
+        }
 
-        if ( --m_Holds == 0 )
+        if (--m_holds == 0)
         {
-            m_Owner = null;
+            m_owner = null;
             notify();
         }
     }//release
 
-
     /**
      * Release the lock N times. <code>release(n)</code> is
      * equivalent in effect to:
@@ -148,20 +156,21 @@
      * @throws Error thrown if not current owner of lock
      *               or has fewer than N holds on the lock
      */
-    public synchronized void release( long n )
+    public synchronized void release(long n)
     {
-        if ( Thread.currentThread() != m_Owner || n > m_Holds )
-            throw new Error( "Illegal Lock usage" );
+        if (Thread.currentThread() != m_owner || n > m_holds)
+        {
+            throw new Error("Illegal Lock usage");
+        }
 
-        m_Holds -= n;
-        if ( m_Holds == 0 )
+        m_holds -= n;
+        if (m_holds == 0)
         {
-            m_Owner = null;
+            m_owner = null;
             notify();
         }
     }//release
 
-
     /**
      * Return the number of unreleased acquires performed
      * by the current thread.
@@ -171,9 +180,10 @@
      */
     public synchronized long holds()
     {
-        if ( Thread.currentThread() != m_Owner )
+        if (Thread.currentThread() != m_owner)
+        {
             return 0;
-        return m_Holds;
+        }
+        return m_holds;
     }//holds
-
-}//class ReentrantLock
+}//class ReentrantLock
\ No newline at end of file

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ServiceMediator.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ServiceMediator.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ServiceMediator.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/ServiceMediator.java Sat Apr 25 14:50:37 2009
@@ -1,22 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import org.apache.felix.shell.ShellService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -27,21 +26,16 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 
-
 /**
  * Implements a mediator pattern class for services from the OSGi container.
  */
 class ServiceMediator
 {
-
-    private BundleContext m_BundleContext;
-
-    private ShellService m_FelixShellService;
-    private Latch m_FelixShellServiceLatch;
-
-    private LogService m_LogService;
-    private Latch m_LogServiceLatch;
-
+    private BundleContext m_bundleContext;
+    private ShellService m_felixShellService;
+    private Latch m_felixShellServiceLatch;
+    private LogService m_logService;
+    private Latch m_logServiceLatch;
 
     /**
      * Returns a reference to the <tt>ShellService</tt> (Felix).
@@ -49,146 +43,137 @@
      * @param wait time in milliseconds to wait for the reference if it isn't available.
      * @return the reference to the <tt>ShellService</tt> as obtained from the OSGi service layer.
      */
-    public ShellService getFelixShellService( long wait )
+    public ShellService getFelixShellService(long wait)
     {
         try
         {
-            if ( wait < 0 )
+            if (wait < 0)
             {
-                m_FelixShellServiceLatch.acquire();
+                m_felixShellServiceLatch.acquire();
             }
-            else if ( wait > 0 )
+            else if (wait > 0)
             {
-                m_FelixShellServiceLatch.attempt( wait );
+                m_felixShellServiceLatch.attempt(wait);
             }
         }
-        catch ( InterruptedException e )
+        catch (InterruptedException e)
         {
-            e.printStackTrace( System.err );
+            e.printStackTrace(System.err);
         }
 
-        return m_FelixShellService;
+        return m_felixShellService;
     }//getFelixShellService
 
-
-    public LogService getLogServiceLatch( long wait )
+    public LogService getLogServiceLatch(long wait)
     {
         try
         {
-            if ( wait < 0 )
+            if (wait < 0)
             {
-                m_LogServiceLatch.acquire();
+                m_logServiceLatch.acquire();
             }
-            else if ( wait > 0 )
+            else if (wait > 0)
             {
-                m_LogServiceLatch.attempt( wait );
+                m_logServiceLatch.attempt(wait);
             }
         }
-        catch ( InterruptedException e )
+        catch (InterruptedException e)
         {
-            e.printStackTrace( System.err );
+            e.printStackTrace(System.err);
         }
-        return m_LogService;
+        return m_logService;
     }//getLogService
 
-
-    public void info( String msg )
+    public void info(String msg)
     {
-        if ( m_LogService != null )
+        if (m_logService != null)
         {
-            m_LogService.log( LogService.LOG_INFO, msg );
+            m_logService.log(LogService.LOG_INFO, msg);
         }
         else
         {
-            sysout( msg );
+            sysout(msg);
         }
     }//info
 
-
-    public void error( String msg, Throwable t )
+    public void error(String msg, Throwable t)
     {
-        if ( m_LogService != null )
+        if (m_logService != null)
         {
-            m_LogService.log( LogService.LOG_ERROR, msg, t );
+            m_logService.log(LogService.LOG_ERROR, msg, t);
         }
         else
         {
-            syserr( msg, t );
+            syserr(msg, t);
         }
     }//error
 
-
-    public void error( String msg )
+    public void error(String msg)
     {
-        if ( m_LogService != null )
+        if (m_logService != null)
         {
-            m_LogService.log( LogService.LOG_ERROR, msg );
+            m_logService.log(LogService.LOG_ERROR, msg);
         }
         else
         {
-            syserr( msg, null );
+            syserr(msg, null);
         }
     }//error
 
-
-    public void debug( String msg )
+    public void debug(String msg)
     {
-        if ( m_LogService != null )
+        if (m_logService != null)
         {
-            m_LogService.log( LogService.LOG_DEBUG, msg );
+            m_logService.log(LogService.LOG_DEBUG, msg);
         }
         else
         {
-            sysout( msg );
+            sysout(msg);
         }
     }//debug
 
-
-    public void warn( String msg )
+    public void warn(String msg)
     {
-        if ( m_LogService != null )
+        if (m_logService != null)
         {
-            m_LogService.log( LogService.LOG_WARNING, msg );
+            m_logService.log(LogService.LOG_WARNING, msg);
         }
         else
         {
-            syserr( msg, null );
+            syserr(msg, null);
         }
     }//warn
 
-
-    private void sysout( String msg )
+    private void sysout(String msg)
     {
         //Assemble String
         StringBuffer sbuf = new StringBuffer();
-        Bundle b = m_BundleContext.getBundle();
-        sbuf.append( b.getHeaders().get( Constants.BUNDLE_NAME ) );
-        sbuf.append( " [" );
-        sbuf.append( b.getBundleId() );
-        sbuf.append( "] " );
-        sbuf.append( msg );
-        System.out.println( sbuf.toString() );
+        Bundle b = m_bundleContext.getBundle();
+        sbuf.append(b.getHeaders().get(Constants.BUNDLE_NAME));
+        sbuf.append(" [");
+        sbuf.append(b.getBundleId());
+        sbuf.append("] ");
+        sbuf.append(msg);
+        System.out.println(sbuf.toString());
     }//sysout
 
-
-    private void syserr( String msg, Throwable t )
+    private void syserr(String msg, Throwable t)
     {
         //Assemble String
         StringBuffer sbuf = new StringBuffer();
-        Bundle b = m_BundleContext.getBundle();
-        sbuf.append( b.getHeaders().get( Constants.BUNDLE_NAME ) );
-        sbuf.append( " [" );
-        sbuf.append( b.getBundleId() );
-        sbuf.append( "] " );
-        sbuf.append( msg );
-        System.err.println( sbuf.toString() );
-        if ( t != null )
+        Bundle b = m_bundleContext.getBundle();
+        sbuf.append(b.getHeaders().get(Constants.BUNDLE_NAME));
+        sbuf.append(" [");
+        sbuf.append(b.getBundleId());
+        sbuf.append("] ");
+        sbuf.append(msg);
+        System.err.println(sbuf.toString());
+        if (t != null)
         {
-            t.printStackTrace( System.err );
+            t.printStackTrace(System.err);
         }
     }//logToSystem
 
-
     /**
      * Activates this mediator to start tracking the required services using the
      * OSGi service layer.
@@ -196,13 +181,13 @@
      * @param bc the bundle's context.
      * @return true if activated successfully, false otherwise.
      */
-    public boolean activate( BundleContext bc )
+    public boolean activate(BundleContext bc)
     {
         //get the context
-        m_BundleContext = bc;
+        m_bundleContext = bc;
 
-        m_FelixShellServiceLatch = createWaitLatch();
-        m_LogServiceLatch = createWaitLatch();
+        m_felixShellServiceLatch = createWaitLatch();
+        m_logServiceLatch = createWaitLatch();
 
         //prepareDefinitions listener
         ServiceListener serviceListener = new ServiceListenerImpl();
@@ -215,7 +200,7 @@
         {
             filter = "(|" + filter + "(objectclass=" + LogService.class.getName() + "))";
         }
-        catch ( Throwable t )
+        catch (Throwable t)
         {
             // ignore
         }
@@ -223,25 +208,24 @@
         try
         {
             //add the listener to the bundle context.
-            bc.addServiceListener( serviceListener, filter );
+            bc.addServiceListener(serviceListener, filter);
 
             //ensure that already registered Service instances are registered with
             //the manager
-            ServiceReference[] srl = bc.getServiceReferences( null, filter );
-            for ( int i = 0; srl != null && i < srl.length; i++ )
+            ServiceReference[] srl = bc.getServiceReferences(null, filter);
+            for (int i = 0; srl != null && i < srl.length; i++)
             {
-                serviceListener.serviceChanged( new ServiceEvent( ServiceEvent.REGISTERED, srl[i] ) );
+                serviceListener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, srl[i]));
             }
         }
-        catch ( InvalidSyntaxException ex )
+        catch (InvalidSyntaxException ex)
         {
-            ex.printStackTrace( System.err );
+            ex.printStackTrace(System.err);
             return false;
         }
         return true;
     }//activate
 
-
     /**
      * Deactivates this mediator, nulling out all references.
      * If called when the bundle is stopped, the framework should actually take
@@ -249,12 +233,11 @@
      */
     public void deactivate()
     {
-        m_FelixShellService = null;
-        m_FelixShellServiceLatch = null;
-        m_BundleContext = null;
+        m_felixShellService = null;
+        m_felixShellServiceLatch = null;
+        m_bundleContext = null;
     }//deactivate
 
-
     /**
      * Creates a simple wait latch to be used for the mechanism that allows entities
      * in the bundles to wait for references.
@@ -271,60 +254,57 @@
      */
     private class ServiceListenerImpl implements ServiceListener
     {
-
-        public void serviceChanged( ServiceEvent ev )
+        public void serviceChanged(ServiceEvent ev)
         {
             ServiceReference sr = ev.getServiceReference();
             Object o = null;
-            switch ( ev.getType() )
+            switch (ev.getType())
             {
                 case ServiceEvent.REGISTERED:
-                    o = m_BundleContext.getService( sr );
-                    if ( o == null )
+                    o = m_bundleContext.getService(sr);
+                    if (o == null)
                     {
                         return;
                     }
-                    else if ( o instanceof ShellService )
+                    else if (o instanceof ShellService)
                     {
-                        m_FelixShellService = ( ShellService ) o;
-                        m_FelixShellServiceLatch.release();
+                        m_felixShellService = (ShellService) o;
+                        m_felixShellServiceLatch.release();
                     }
-                    else if ( o instanceof LogService )
+                    else if (o instanceof LogService)
                     {
-                        m_LogService = ( LogService ) o;
-                        m_LogServiceLatch.release();
+                        m_logService = (LogService) o;
+                        m_logServiceLatch.release();
                     }
                     else
                     {
-                        m_BundleContext.ungetService( sr );
+                        m_bundleContext.ungetService(sr);
                     }
                     break;
                 case ServiceEvent.UNREGISTERING:
-                    o = m_BundleContext.getService( sr );
-                    if ( o == null )
+                    o = m_bundleContext.getService(sr);
+                    if (o == null)
                     {
                         return;
                     }
-                    else if ( o instanceof ShellService )
+                    else if (o instanceof ShellService)
                     {
-                        m_FelixShellService = null;
-                        m_FelixShellServiceLatch = createWaitLatch();
+                        m_felixShellService = null;
+                        m_felixShellServiceLatch = createWaitLatch();
                     }
-                    else if ( o instanceof LogService )
+                    else if (o instanceof LogService)
                     {
-                        m_LogService = null;
-                        m_LogServiceLatch = createWaitLatch();
+                        m_logService = null;
+                        m_logServiceLatch = createWaitLatch();
                     }
                     else
                     {
-                        m_BundleContext.ungetService( sr );
+                        m_bundleContext.ungetService(sr);
                     }
                     break;
             }
         }
     }//inner class ServiceListenerImpl
-
     public static long WAIT_UNLIMITED = -1;
     public static long NO_WAIT = 0;
-
 }//class ServiceMediator

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java Sat Apr 25 14:50:37 2009
@@ -1,22 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.PrintStream;
@@ -24,7 +23,6 @@
 
 import org.apache.felix.shell.ShellService;
 
-
 /**
  * Implements the shell.
  * <p>
@@ -39,126 +37,122 @@
  */
 class Shell implements Runnable
 {
-
     private Listener m_owner;
-    private Socket m_Socket;
-    private AtomicInteger m_UseCounter;
-
+    private Socket m_socket;
+    private AtomicInteger m_useCounter;
 
-    public Shell( Listener owner, Socket s, AtomicInteger counter )
+    public Shell(Listener owner, Socket s, AtomicInteger counter)
     {
         m_owner = owner;
-        m_Socket = s;
-        m_UseCounter = counter;
+        m_socket = s;
+        m_useCounter = counter;
     }//constructor
 
     void terminate()
     {
         // called by Listener.deactivate() to terminate this session
-        exit( "\r\nFelix Remote Shell Console Terminating" );
+        exit("\r\nFelix Remote Shell Console Terminating");
     }//terminate
-    
+
     /**
      * Runs the shell.
      */
     public void run()
     {
-        m_owner.registerConnection( this );
-        
+        m_owner.registerConnection(this);
+
         try
         {
-            PrintStream out = new TerminalPrintStream( m_Socket.getOutputStream() );
-            BufferedReader in = new BufferedReader( new TerminalReader( m_Socket.getInputStream(), out ) );
+            PrintStream out = new TerminalPrintStream(m_socket.getOutputStream());
+            BufferedReader in = new BufferedReader(new TerminalReader(m_socket.getInputStream(), out));
             ReentrantLock lock = new ReentrantLock();
 
             // Print welcome banner.
             out.println();
-            out.println( "Felix Remote Shell Console:" );
-            out.println( "============================" );
-            out.println( "" );
+            out.println("Felix Remote Shell Console:");
+            out.println("============================");
+            out.println("");
 
             do
             {
-                out.print( "-> " );
+                out.print("-> ");
                 String line = "";
                 try
                 {
                     line = in.readLine();
                     //make sure to capture end of stream
-                    if ( line == null )
+                    if (line == null)
                     {
-                        out.println( "exit" );
+                        out.println("exit");
                         return;
                     }
                 }
-                catch ( Exception ex )
+                catch (Exception ex)
                 {
                     return;
                 }
 
                 line = line.trim();
-                if ( line.equalsIgnoreCase( "exit" ) || line.equalsIgnoreCase( "disconnect" ) )
+                if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("disconnect"))
                 {
                     return;
                 }
 
-                ShellService shs = Activator.getServices().getFelixShellService( ServiceMediator.NO_WAIT );
+                ShellService shs = Activator.getServices().getFelixShellService(ServiceMediator.NO_WAIT);
                 try
                 {
                     lock.acquire();
-                    shs.executeCommand( line, out, out );
+                    shs.executeCommand(line, out, out);
                 }
-                catch ( Exception ex )
+                catch (Exception ex)
                 {
-                    Activator.getServices().error( "Shell::run()", ex );
+                    Activator.getServices().error("Shell::run()", ex);
                 }
                 finally
                 {
                     lock.release();
                 }
             }
-            while ( true );
+            while (true);
         }
-        catch ( IOException ex )
+        catch (IOException ex)
         {
-            Activator.getServices().error( "Shell::run()", ex );
+            Activator.getServices().error("Shell::run()", ex);
         }
         finally
         {
             // no need to clean up in/out, since exit does it all
-            exit( null );
+            exit(null);
         }
     }//run
 
-
     private void exit(String message)
     {
         // farewell message
         try
         {
-            PrintStream out = new TerminalPrintStream( m_Socket.getOutputStream() );
-            if ( message != null )
+            PrintStream out = new TerminalPrintStream(m_socket.getOutputStream());
+            if (message != null)
             {
-                out.println( message );
+                out.println(message);
             }
-            out.println( "Good Bye!" );
+            out.println("Good Bye!");
             out.close();
         }
-        catch ( IOException ioe )
+        catch (IOException ioe)
         {
             // ignore
         }
 
         try
         {
-            m_Socket.close();
+            m_socket.close();
         }
-        catch ( IOException ex )
+        catch (IOException ex)
         {
-            Activator.getServices().error( "Shell::exit()", ex );
+            Activator.getServices().error("Shell::exit()", ex);
         }
-        m_owner.unregisterConnection( this );
-        m_UseCounter.decrement();
+        m_owner.unregisterConnection(this);
+        m_useCounter.decrement();
     }//exit
-
 }//class Shell

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java Sat Apr 25 14:50:37 2009
@@ -1,75 +1,68 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
 
-
 /**
  * Class implementing a <tt>TerminalPrintStream</tt>.
  */
 class TerminalPrintStream extends PrintStream
 {
-
     /**
      * Constructs a new instance wrapping the given <tt>OutputStream</tt>.
      *
      * @param tout the <tt>OutputStream</tt> to be wrapped.
      */
-    public TerminalPrintStream( OutputStream tout )
+    public TerminalPrintStream(OutputStream tout)
     {
-        super( tout );
+        super(tout);
     }//constructor
 
-
-    public void print( String str )
+    public void print(String str)
     {
         try
         {
             byte[] bytes = str.getBytes();
-            out.write( bytes, 0, bytes.length );
+            out.write(bytes, 0, bytes.length);
             flush();
         }
-        catch ( IOException ex )
+        catch (IOException ex)
         {
-            Activator.getServices().error( "TerminalPrintStream::print()", ex );
+            Activator.getServices().error("TerminalPrintStream::print()", ex);
         }
     }//print
 
-
-    public void println( String str )
+    public void println(String str)
     {
-        print( str + "\r\n" );
+        print(str + "\r\n");
     }//println
 
-
     public void flush()
     {
         try
         {
             out.flush();
         }
-        catch ( IOException ex )
+        catch (IOException ex)
         {
-            Activator.getServices().error( "TerminalPrintStream::println()", ex );
+            Activator.getServices().error("TerminalPrintStream::println()", ex);
         }
     }//flush
-
 }//class TerminalPrintStream

Modified: felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java?rev=768539&r1=768538&r2=768539&view=diff
==============================================================================
--- felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java (original)
+++ felix/trunk/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java Sat Apr 25 14:50:37 2009
@@ -1,28 +1,26 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.felix.shell.remote;
 
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.io.Reader;
 
-
 /**
  * Class implementing a terminal reader adapter
  * originally designed for the BeanShell Interpreter.
@@ -31,20 +29,17 @@
  */
 class TerminalReader extends Reader
 {
+    protected InputStream m_in;
+    protected PrintStream m_out;
+    protected boolean m_echo = false;
+    protected boolean m_eof = false;
 
-    protected InputStream m_In;
-    protected PrintStream m_Out;
-    protected boolean m_Echo = false;
-    protected boolean m_EOF = false;
-
-
-    public TerminalReader( InputStream in, PrintStream out )
+    public TerminalReader(InputStream in, PrintStream out)
     {
-        m_In = in;
-        m_Out = out;
+        m_in = in;
+        m_out = out;
     }//TerminalReader
 
-
     /**
      * Tests if this <tt>TerminalReader</tt> will echo
      * the character input to the terminal.
@@ -53,10 +48,9 @@
      */
     public boolean isEcho()
     {
-        return m_Echo;
+        return m_echo;
     }//isEcho
 
-
     /**
      * Sets if this <tt>TerminalReader</tt> will echo
      * the character input to the terminal.
@@ -70,44 +64,43 @@
      *
      * @param echo true if echo, false otherwise.
      */
-    public void setEcho( boolean echo )
+    public void setEcho(boolean echo)
     {
-        m_Echo = echo;
+        m_echo = echo;
     }//setEcho
 
-
-    public int read( char[] chars, int off, int len ) throws IOException
+    public int read(char[] chars, int off, int len) throws IOException
     {
-        if ( m_EOF )
+        if (m_eof)
         {
             return -1;
         }
-        for ( int i = off; i < off + len; i++ )
+        for (int i = off; i < off + len; i++)
         {
-            int ch = m_In.read();
+            int ch = m_in.read();
             //shortcut for EOT and simple EOF
-            if ( ch == EOT || ( i == off && ch == -1 ) )
+            if (ch == EOT || (i == off && ch == -1))
             {
                 return -1;
             }
-            chars[i] = ( char ) ch;
-            if ( ch == -1 || ch == 10 || ch == 13 )
+            chars[i] = (char) ch;
+            if (ch == -1 || ch == 10 || ch == 13)
             {
-                m_EOF = ch == -1; //store EOF
+                m_eof = ch == -1; //store EOF
                 int read = i - off + 1;
-                if ( m_Echo )
+                if (m_echo)
                 {
-                    m_Out.write( CRLF );
+                    m_out.write(CRLF);
                 }
                 return read;
             }
             //naive backspace handling
-            if ( ch == BS || ch == DEL )
+            if (ch == BS || ch == DEL)
             {
-                if ( i > off )
+                if (i > off)
                 {
                     i = i - 2;
-                    moveLeft( 1 );
+                    moveLeft(1);
                     eraseToEndOfLine();
                 }
                 else
@@ -116,48 +109,45 @@
                     bell();
                 }
             }
-            else if ( ch == CTRL_U )
+            else if (ch == CTRL_U)
             {
-                moveLeft( i - off );
+                moveLeft(i - off);
                 eraseToEndOfLine();
                 i = off - 1;
             }
             else
             {
-                if ( m_Echo )
+                if (m_echo)
                 {
-                    m_Out.write( chars[i] );
+                    m_out.write(chars[i]);
                 }
             }
         }
         return len;
     }//read
 
-
     /**
      * Writes the NVT BEL character to the output.
      */
     private void bell()
     {
-        m_Out.write( BEL );
-        m_Out.flush();
+        m_out.write(BEL);
+        m_out.flush();
     }//bell
 
-
     /**
      * Writes the standard vt100/ansi cursor moving code to the output.
      *
      * @param i the number of times the cursor should be moved left.
      * @throws IOException if I/O fails.
      */
-    private void moveLeft( int i ) throws IOException
+    private void moveLeft(int i) throws IOException
     {
-        CURSOR_LEFT[2] = Byte.decode( Integer.toString( i ) ).byteValue();
-        m_Out.write( CURSOR_LEFT );
-        m_Out.flush();
+        CURSOR_LEFT[2] = Byte.decode(Integer.toString(i)).byteValue();
+        m_out.write(CURSOR_LEFT);
+        m_out.flush();
     }//moveLeft
 
-
     /**
      * Writes the standard vt100/ansi sequence for erasing to the end of the current line.
      *
@@ -165,11 +155,10 @@
      */
     private void eraseToEndOfLine() throws IOException
     {
-        m_Out.write( ERASE_TEOL );
-        m_Out.flush();
+        m_out.write(ERASE_TEOL);
+        m_out.flush();
     }//eraseToEndOfLine
 
-
     /**
      * Closes this reader.
      * Note: will close the input, but not the output.
@@ -178,59 +167,55 @@
      */
     public void close() throws IOException
     {
-        m_In.close();
+        m_in.close();
     }//close
-
     /**
      * <b>Bell</b><br>
      * The ANSI defined byte code for the NVT bell.
      */
     public static final byte BEL = 7;
-
     /**
      * <b>BackSpace</b><br>
      * The ANSI defined byte code of backspace.
      */
     public static final byte BS = 8;
-
     /**
      * <b>Delete</b><br>
      * The ANSI defined byte code of delete.
      */
     public static final byte DEL = 127;
-
     /**
      * CTRL-u
      */
     public static final byte CTRL_U = 21;
-
     /**
      * Escape character.
      */
     private static byte ESC = 27;
-
     /**
      * vt100/ansi standard sequence for moving the cursor left.
      */
     private static byte[] CURSOR_LEFT =
-        { ESC, '[', '1', 'D' };
-
+    {
+        ESC, '[', '1', 'D'
+    };
     /**
      * vt100/ansi standard sequence for erasing everything from the actual cursor to
      * the end of the current line.
      */
     private static byte[] ERASE_TEOL =
-        { ESC, '[', 'K' };
-
+    {
+        ESC, '[', 'K'
+    };
     /**
      * Standard NVT line break, which HAS TO BE CR and LF.
      */
     private static byte[] CRLF =
-        { '\r', '\n' };
-
+    {
+        '\r', '\n'
+    };
     /**
      * Standard ASCII end of transmission.
      */
     private static byte EOT = 4;
-
 }//class TerminalReader