KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > j2ee > session > SubscribingInterceptor


1 // ========================================================================
2
// $Id: SubscribingInterceptor.java,v 1.5 2004/06/22 16:23:44 jules_gosnell Exp $
3
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.j2ee.session;
17
18 //----------------------------------------
19

20 import java.rmi.RemoteException JavaDoc;
21
22 import org.jfox.ioc.logger.Logger;
23
24 //----------------------------------------
25

26
27 // hook SubscribingInterceptor to AbstractReplicatedStore
28
// lose ReplicatedState
29

30 public class SubscribingInterceptor
31   extends StateInterceptor
32 {
33   protected static final Logger _log=Logger.getLogger(SubscribingInterceptor.class);
34
35   protected AbstractReplicatedStore
36     getStore()
37   {
38     AbstractReplicatedStore store=null;
39     try
40     {
41       store=(AbstractReplicatedStore)getManager().getStore();
42     }
43     catch (Exception JavaDoc e)
44     {
45       _log.error("could not get AbstractReplicatedStore");
46     }
47
48     return store;
49   }
50
51   //----------------------------------------
52

53   // this Interceptor is stateful - it is the dispatch point for
54
// change notifications targeted at the session that it wraps.
55

56   public void
57     start()
58   {
59     try
60     {
61       AbstractReplicatedStore store = getStore();
62       if (store != null)
63       getStore().subscribe(getId(), this);
64     }
65     catch (RemoteException JavaDoc e)
66     {
67       _log.error("could not get my ID", e);
68     }
69   }
70
71   public void
72     stop()
73   {
74     try
75     {
76       AbstractReplicatedStore store = getStore();
77       if (store != null)
78         store.unsubscribe(getId());
79     }
80     catch (RemoteException JavaDoc e)
81     {
82       _log.error("could not get my ID", e);
83     }
84   }
85 }
86
Popular Tags