You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2012/05/19 20:23:18 UTC
svn commit: r1340528 - in /mina/sshd/trunk/sshd-core/src:
main/java/org/apache/sshd/SshServer.java
test/java/org/apache/sshd/SshServerTest.java
Author: gnodet
Date: Sat May 19 18:23:18 2012
New Revision: 1340528
URL: http://svn.apache.org/viewvc?rev=1340528&view=rev
Log:
[SSHD-157] SshServer.stop should be idempotent
Added:
mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java?rev=1340528&r1=1340527&r2=1340528&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java Sat May 19 18:23:18 2012
@@ -359,13 +359,15 @@ public class SshServer extends AbstractF
}
public void stop(boolean immediately) throws InterruptedException {
- acceptor.setCloseOnDeactivation(false);
- acceptor.unbind();
List<AbstractSession> sessions = new ArrayList<AbstractSession>();
- for (IoSession ioSession : acceptor.getManagedSessions().values()) {
- AbstractSession session = AbstractSession.getSession(ioSession, true);
- if (session != null) {
- sessions.add(session);
+ if (acceptor != null) {
+ acceptor.setCloseOnDeactivation(false);
+ acceptor.unbind();
+ for (IoSession ioSession : acceptor.getManagedSessions().values()) {
+ AbstractSession session = AbstractSession.getSession(ioSession, true);
+ if (session != null) {
+ sessions.add(session);
+ }
}
}
final CountDownLatch latch = new CountDownLatch(sessions.size());
@@ -380,7 +382,9 @@ public class SshServer extends AbstractF
if (!immediately) {
latch.await();
}
- acceptor.dispose();
+ if (acceptor != null) {
+ acceptor.dispose();
+ }
acceptor = null;
if (shutdownExecutor && executor != null) {
executor.shutdown();
Added: mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java?rev=1340528&view=auto
==============================================================================
--- mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java (added)
+++ mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java Sat May 19 18:23:18 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.sshd;
+
+import org.junit.Test;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class SshServerTest {
+ @Test
+ public void stopMethodShouldBeIdempotent() throws Exception {
+ SshServer sshd = new SshServer();
+ sshd.stop();
+ sshd.stop();
+ sshd.stop();
+ }
+}