Few comments below

On Wed, Jan 4, 2012 at 8:56 PM,  <papega...@apache.org> wrote:
> Updated Branches:
>  refs/heads/master 184e41e1f -> f3edce1a7
>
>
> WICKET-4212: Add ISessionStore BindListener
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f3edce1a
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f3edce1a
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f3edce1a
>
> Branch: refs/heads/master
> Commit: f3edce1a75ac4bcc3978e3056354a1a30c0ffd1b
> Parents: 35c66b2
> Author: Emond Papegaaij <papega...@apache.org>
> Authored: Wed Nov 9 15:31:56 2011 +0100
> Committer: Emond Papegaaij <papega...@apache.org>
> Committed: Wed Jan 4 18:01:17 2012 +0100
>
> ----------------------------------------------------------------------
>  .../org/apache/wicket/mock/MockSessionStore.java   |   23 +++++++--
>  .../apache/wicket/session/HttpSessionStore.java    |   34 ++++++++++++++
>  .../org/apache/wicket/session/ISessionStore.java   |   36 +++++++++++++++
>  3 files changed, 88 insertions(+), 5 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/f3edce1a/wicket-core/src/main/java/org/apache/wicket/mock/MockSessionStore.java
> ----------------------------------------------------------------------
> diff --git 
> a/wicket-core/src/main/java/org/apache/wicket/mock/MockSessionStore.java 
> b/wicket-core/src/main/java/org/apache/wicket/mock/MockSessionStore.java
> index 8b78ae0..523c5a4 100644
> --- a/wicket-core/src/main/java/org/apache/wicket/mock/MockSessionStore.java
> +++ b/wicket-core/src/main/java/org/apache/wicket/mock/MockSessionStore.java
> @@ -46,6 +46,9 @@ public class MockSessionStore implements ISessionStore
>
>        private String sessionId;
>        private final Map<String, Serializable> attributes = new 
> HashMap<String, Serializable>();
> +       private final Set<UnboundListener> unboundListeners = new 
> CopyOnWriteArraySet<UnboundListener>();
> +       private final Set<BindListener> bindListeners = new 
> CopyOnWriteArraySet<BindListener>();
> +
>        private Session session;
>
>        @Override
> @@ -107,8 +110,6 @@ public class MockSessionStore implements ISessionStore
>                return session;
>        }
>
> -       private final Set<UnboundListener> unboundListeners = new 
> CopyOnWriteArraySet<UnboundListener>();
> -
>        @Override
>        public void registerUnboundListener(UnboundListener listener)
>        {
> @@ -121,9 +122,6 @@ public class MockSessionStore implements ISessionStore
>                attributes.remove(name);
>        }
>
> -       /**
> -        * @see org.apache.wicket.session.ISessionStore#getUnboundListener()
> -        */
>        @Override
>        public final Set<UnboundListener> getUnboundListener()
>        {
> @@ -142,6 +140,21 @@ public class MockSessionStore implements ISessionStore
>                unboundListeners.remove(listener);
>        }
>
> +       public void registerBindListener(BindListener listener)
> +       {
> +               bindListeners.add(listener);
> +       }
> +
> +       public void unregisterBindListener(BindListener listener)
> +       {
> +               bindListeners.remove(listener);
> +       }
> +
> +       public Set<BindListener> getBindListeners()
> +       {
> +               return Collections.unmodifiableSet(bindListeners);
> +       }
> +
>        @Override
>        public void flushSession(Request request, Session session)
>        {
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/f3edce1a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
> ----------------------------------------------------------------------
> diff --git 
> a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java 
> b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
> index a8403f9..3b8a4b3 100644
> --- 
> a/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
> +++ 
> b/wicket-core/src/main/java/org/apache/wicket/session/HttpSessionStore.java
> @@ -55,6 +55,8 @@ public class HttpSessionStore implements ISessionStore
>        /** */
>        private final Set<UnboundListener> unboundListeners = new 
> CopyOnWriteArraySet<UnboundListener>();
>
> +       private final Set<BindListener> bindListeners = new 
> CopyOnWriteArraySet<BindListener>();

Is it a good idea to make use of
org.apache.wicket.util.listener.ListenerCollection ?
See org.apache.wicket.ApplicationListenerCollection for example.
ListenerCollection uses CopyOnWriteArrayList but I don't think this is
a problem here.

The old is 'Unbound', the new is 'Bind'.
I think the new should be 'Bound' because the listener is invoked
after the binding.
> +
>        /**
>         * Construct.
>         */
> @@ -103,6 +105,10 @@ public class HttpSessionStore implements ISessionStore
>                {
>                        // call template method
>                        onBind(request, newSession);
> +                       for (BindListener listener : getBindListeners())
> +                       {
> +                               listener.bindingSession(request, newSession);

-> sessionBound()

> +                       }
>
>                        HttpSession httpSession = getHttpSession(request, 
> false);
>
> @@ -367,6 +373,34 @@ public class HttpSessionStore implements ISessionStore
>        }
>
>        /**
> +        * Registers listener invoked when session is bound.
> +        *
> +        * @param listener
> +        */
> +       public void registerBindListener(BindListener listener)
> +       {
> +               bindListeners.add(listener);
> +       }
> +
> +       /**
> +        * Unregisters listener invoked when session is bound.
> +        *
> +        * @param listener
> +        */
> +       public void unregisterBindListener(BindListener listener)
> +       {
> +               bindListeners.remove(listener);
> +       }
> +
> +       /**
> +        * @return The list of registered bind listeners
> +        */
> +       public Set<BindListener> getBindListeners()
> +       {
> +               return Collections.unmodifiableSet(bindListeners);
> +       }
> +
> +       /**
>         * Reacts on unbinding from the session by cleaning up the session 
> related data.
>         */
>        protected static final class SessionBindingListener
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/f3edce1a/wicket-core/src/main/java/org/apache/wicket/session/ISessionStore.java
> ----------------------------------------------------------------------
> diff --git 
> a/wicket-core/src/main/java/org/apache/wicket/session/ISessionStore.java 
> b/wicket-core/src/main/java/org/apache/wicket/session/ISessionStore.java
> index f4894d7..7a5d623 100644
> --- a/wicket-core/src/main/java/org/apache/wicket/session/ISessionStore.java
> +++ b/wicket-core/src/main/java/org/apache/wicket/session/ISessionStore.java
> @@ -180,4 +180,40 @@ public interface ISessionStore
>         * @return The list of registered unbound listeners
>         */
>        Set<UnboundListener> getUnboundListener();
> +
> +       /**
> +        * Listener invoked when session is bound.
> +        */
> +       public interface BindListener
> +       {
> +               /**
> +                * Informs the listener that a session is about to be bound. 
> Note that this method is also
> +                * called for {@link Session#isTemporary() temporary 
> sessions}.
> +                *
> +                * @param request
> +                *            The request the session is bound in
> +                * @param newSession
> +                *            The session that will be bound
> +                */
> +               void bindingSession(Request request, Session newSession);
> +       }
> +
> +       /**
> +        * Registers listener invoked when session is bound.
> +        *
> +        * @param listener
> +        */
> +       void registerBindListener(BindListener listener);
> +
> +       /**
> +        * Unregisters listener invoked when session is bound.
> +        *
> +        * @param listener
> +        */
> +       void unregisterBindListener(BindListener listener);
> +
> +       /**
> +        * @return The list of registered bind listeners
> +        */
> +       Set<BindListener> getBindListeners();
>  }
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

Reply via email to