Merge "creating a default subnet"
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / handler / ssh / client / Invoker.java
1 package org.opendaylight.controller.netconf.util.handler.ssh.client;
2
3 import java.io.IOException;
4
5 /**
6  * Abstract class providing mechanism of invoking various SSH level services.
7  * Class is not allowed to be extended, as it provides its own implementations via instance initiators.
8  */
9 public abstract class Invoker {
10     private boolean invoked = false;
11
12     private Invoker(){}
13
14     protected boolean isInvoked() {
15         return invoked;
16     }
17
18     abstract void invoke(SshSession session) throws IOException;
19
20     /**
21      * Invoker implementation to invokes subsystem SSH service.
22      *
23      * @param subsystem
24      * @return
25      */
26     public static Invoker subsystem(final String subsystem) {
27         return new Invoker() {
28             @Override
29             void invoke(SshSession session) throws IOException {
30                 if (isInvoked() == true) throw new IllegalStateException("Already invoked.");
31
32                 session.startSubSystem(subsystem);
33             }
34         };
35     }
36 }