You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2017/10/06 16:51:20 UTC

[03/17] incubator-guacamole-client git commit: GUACAMOLE-364: add facade used to wrap extension listeners

GUACAMOLE-364: add facade used to wrap extension listeners


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/dca78623
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/dca78623
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/dca78623

Branch: refs/heads/master
Commit: dca7862351fd4c27e82ecaf1cf540180501f48ec
Parents: 6f89a0b
Author: Carl Harris <ce...@vt.edu>
Authored: Wed Aug 16 06:54:55 2017 -0400
Committer: Carl Harris <ce...@vt.edu>
Committed: Wed Aug 16 06:54:55 2017 -0400

----------------------------------------------------------------------
 .../guacamole/extension/ListenerFacade.java     | 135 +++++++++++++++++++
 .../guacamole/extension/ListenerProvider.java   |  37 +++++
 2 files changed, 172 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/dca78623/guacamole/src/main/java/org/apache/guacamole/extension/ListenerFacade.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/ListenerFacade.java b/guacamole/src/main/java/org/apache/guacamole/extension/ListenerFacade.java
new file mode 100644
index 0000000..278b2a9
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/extension/ListenerFacade.java
@@ -0,0 +1,135 @@
+/*
+ * 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.guacamole.extension;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.event.AuthenticationFailureEvent;
+import org.apache.guacamole.net.event.AuthenticationSuccessEvent;
+import org.apache.guacamole.net.event.TunnelCloseEvent;
+import org.apache.guacamole.net.event.TunnelConnectEvent;
+import org.apache.guacamole.net.event.listener.*;
+
+/**
+ * Provides a wrapper around a Listener subclass, allowing listener
+ * extensions to be bound without regard for which specific listener interfaces
+ * are implemented.
+ */
+class ListenerFacade implements ListenerProvider {
+
+    private final Listener delegate;
+
+    /**
+     * Creates a new ListenerFacade which delegates all listener methods
+     * calls to an instance of the given Listener subclass. If
+     * an instance of the given class cannot be created, creation of this
+     * facade will still succeed. Errors will be logged at the time listener
+     * creation fails, but subsequent events directed to the listener will be
+     * silently dropped.
+     *
+     * @param listenerClass
+     *     The Listener subclass to instantiate.
+     */
+    public ListenerFacade(Class<? extends Listener> listenerClass) {
+        delegate = ProviderFactory.newInstance("listener", listenerClass);
+    }
+
+    /**
+     * Notifies the delegate listener of an authentication success event, if the
+     * listener implements the AuthenticationSuccessListener interface.
+     *
+     * @param
+     *      e The AuthenticationSuccessEvent describing the authentication
+     *        success that just occurred.
+     * @return
+     *      false if the delegate listener rejects the successful authentication,
+     *      else true
+     *
+     * @throws GuacamoleException
+     *      if the delegate listener throws this exception
+     */
+    @Override
+    public boolean authenticationSucceeded(AuthenticationSuccessEvent e)
+            throws GuacamoleException {
+        return !(delegate instanceof AuthenticationSuccessListener)
+                || ((AuthenticationSuccessListener) delegate).authenticationSucceeded(e);
+    }
+
+    /**
+     * Notifies the delegate listener of an authentication failure event, if the
+     * listener implements the AuthenticationSuccessListener interface.
+     *
+     * @param
+     *      e The AuthenticationFailureEvent describing the authentication
+     *        failure that just occurred.
+     *
+     * @throws GuacamoleException
+     *      if the delegate listener throws this exception
+     */
+    @Override
+    public void authenticationFailed(AuthenticationFailureEvent e)
+            throws GuacamoleException {
+        if (delegate instanceof AuthenticationFailureListener) {
+            ((AuthenticationFailureListener) delegate).authenticationFailed(e);
+        }
+    }
+
+    /**
+     * Notifies the delegate listener of a tunnel connected event, if the
+     * listener implements the TunnelConnectListener interface.
+     *
+     * @param
+     *      e The TunnelConnectEvent describing the tunnel that was just connected
+
+     * @return
+     *      false if the delegate listener rejects the tunnel connection,
+     *      else true
+     *
+     * @throws GuacamoleException
+     *      if the delegate listener throws this exception
+     */
+    @Override
+    public boolean tunnelConnected(TunnelConnectEvent e)
+            throws GuacamoleException {
+        return !(delegate instanceof TunnelConnectListener)
+                || ((TunnelConnectListener) delegate).tunnelConnected(e);
+    }
+
+    /**
+     * Notifies the delegate listener of a tunnel close event, if the
+     * listener implements the TunnelCloseListener interface.
+     *
+     * @param
+     *      e The TunnelCloseEvent describing the tunnel that is to be close
+
+     * @return
+     *      false if the delegate listener rejects the tunnel close request,
+     *      else true
+     *
+     * @throws GuacamoleException
+     *      if the delegate listener throws this exception
+     */
+    @Override
+    public boolean tunnelClosed(TunnelCloseEvent e) throws GuacamoleException {
+        return !(delegate instanceof TunnelCloseListener)
+                || ((TunnelCloseListener) delegate).tunnelClosed(e);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/dca78623/guacamole/src/main/java/org/apache/guacamole/extension/ListenerProvider.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/ListenerProvider.java b/guacamole/src/main/java/org/apache/guacamole/extension/ListenerProvider.java
new file mode 100644
index 0000000..0b3a747
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/extension/ListenerProvider.java
@@ -0,0 +1,37 @@
+/*
+ * 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.guacamole.extension;
+
+import org.apache.guacamole.net.event.listener.AuthenticationFailureListener;
+import org.apache.guacamole.net.event.listener.AuthenticationSuccessListener;
+import org.apache.guacamole.net.event.listener.TunnelCloseListener;
+import org.apache.guacamole.net.event.listener.TunnelConnectListener;
+
+/**
+ * A provider of an event listener. While an implementation of this interface
+ * must implement all of the specified listener interfaces, an implementation
+ * may selectively deliver event notifications to an underlying delegate based
+ * on the specific listener interfaces implemented by the delegate.
+ */
+public interface ListenerProvider extends AuthenticationSuccessListener,
+        AuthenticationFailureListener, TunnelConnectListener,
+        TunnelCloseListener {
+}