Feedback on this would be appreciated, especially with regards to the
notification mechanism. I'm familiar with JMS, but that means clustering
would depend on a JMS server (obviously). I've never used javagroups,
but it seems to be a popular solution to this kind of issue. I think I'd
like to use HTTP, and with the event support that's being worked on this
seems feasable, but I couldn't find any examples of how to send an event
to the webdav servlet.

-James

>>> [EMAIL PROTECTED] 07/22/04 12:23 AM >>>
masonjm     2004/07/22 00:23:59

  Modified:    src/share/org/apache/slide/store ExtendedStore.java
  Added:       src/share/org/apache/slide/event UriModifiedEvent.java
                        UriModifiedListener.java
                        UncacheModifiedUriListener.java
                        ContentModifiedNotifier.java
  Log:
  Initial work for cluster notifications.
  The Events framework is here, along with a change to ExtendedStore to
allow removing objects from the cache.
  Still to do is the actual notification mechanism (http, jms,
javagroups, something...).
  
  Revision  Changes    Path
  1.1                 
jakarta-slide/src/share/org/apache/slide/event/UriModifiedEvent.java
  
  Index: UriModifiedEvent.java
  ===================================================================
  /*
   *  Copyright 1999-2004 The Apache Software Foundation 
   *
   * Licensed 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.slide.event;
  
  import java.util.EventListener;
  import java.util.EventObject;
  
  import org.apache.slide.common.Uri;
  
  /**
   * Indicates that an Uri has been somehow modified.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">James Mason</a>
   */
  public class UriModifiedEvent extends EventObject {
  
        public static final UriModified URIMODIFIED = new UriModified();
        public final static AbstractEventMethod[] methods = new
AbstractEventMethod[] { URIMODIFIED };
        
        public static final String GROUP = "urimodified";
        
        private Uri uri;
        
        public UriModifiedEvent(Object source, Uri uri) {
                super(source);
                this.uri = uri;
        }
        
        public Uri getUri() {
                return uri;
        }
        
        public static class UriModified extends EventMethod {
  
                public UriModified() {
                        super( GROUP, "urimodified" );
                }
  
                public void fireEvent( EventListener listener,
EventObject event ) {
                        if ( listener instanceof UriModifiedListener )
((UriModifiedListener)listener).modified((UriModifiedEvent)event);
                }
                
        }
  }
  
  
  
  1.1                 
jakarta-slide/src/share/org/apache/slide/event/UriModifiedListener.java
  
  Index: UriModifiedListener.java
  ===================================================================
  /*
   *  Copyright 1999-2004 The Apache Software Foundation 
   *
   * Licensed 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.slide.event;
  
  import java.util.EventListener;
  
  /**
   * Classes that implement this interface listen for UriModifiedEvents.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">James Mason</a>
   */
  public interface UriModifiedListener extends EventListener {
        
        public void modified( UriModifiedEvent event );
  
  }
  
  
  
  1.1                 
jakarta-slide/src/share/org/apache/slide/event/UncacheModifiedUriListener.java
  
  Index: UncacheModifiedUriListener.java
  ===================================================================
  /*
   *  Copyright 1999-2004 The Apache Software Foundation 
   *
   * Licensed 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.slide.event;
  
  import org.apache.slide.common.Domain;
  import org.apache.slide.store.ExtendedStore;
  import org.apache.slide.store.Store;
  import org.apache.slide.util.logger.Logger;
  
  /**
   * In response to an UriModifiedEvent this listener asks the Uri's
Store to remove the Uri
   * from its cache.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">James Mason</a>
   */
  public class UncacheModifiedUriListener implements UriModifiedListener
{
        
        public static final String LOG_CHANNEL =
UncacheModifiedUriListener.class.getName();
        
        public UncacheModifiedUriListener() {
                Domain.log( "Creating UncacheModifiedUriListener.",
LOG_CHANNEL, Logger.DEBUG );
        }
  
        public void modified(UriModifiedEvent event) {
                Store store = event.getUri().getStore();
                /*
                 * TODO: Moving the cache methods on ExtendedStore into
their own interface (say CachingStore)
                 * would make this more portable.
                 */
                if ( store instanceof ExtendedStore ) {
                        ((ExtendedStore)store).removeObjectFromCache(
event.getUri() );
                } else {
                        Domain.log(
                                "Invalid store type " + store + " while
uncaching " + event.getUri().toString(),
                                LOG_CHANNEL,
                                Logger.WARNING );
                }
        }
  
  }
  
  
  
  1.1                 
jakarta-slide/src/share/org/apache/slide/event/ContentModifiedNotifier.java
  
  Index: ContentModifiedNotifier.java
  ===================================================================
  /*
   *  Copyright 1999-2004 The Apache Software Foundation 
   *
   * Licensed 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.slide.event;
  
  import org.apache.slide.common.Domain;
  import org.apache.slide.common.Uri;
  import org.apache.slide.util.conf.Configurable;
  import org.apache.slide.util.conf.Configuration;
  import org.apache.slide.util.conf.ConfigurationException;
  import org.apache.slide.util.logger.Logger;
  
  /**
   * Fires an UriModifiedEvent whenever an Uri is modified.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">James Mason</a>
   */
  public class ContentModifiedNotifier extends ContentAdapter implements
                Configurable {
        
        protected static final String LOG_CHANNEL =
ContentModifiedNotifier.class.getName();
        
        public ContentModifiedNotifier() {
                Domain.log( "Creating ContentModifiedNotifier",
LOG_CHANNEL, Logger.DEBUG );
        }
  
        public void create( ContentEvent event ) {
                notify( event );
        }
        
        public void fork( ContentEvent event ) {
                // TODO: find out what "fork" does and if it needs
watching.
                notify( event );
        }
        
        public void merge( ContentEvent event ) {
                // TODO: find out what "merge" does and if it needs
watching.
                notify( event );
        }
       
        public void remove( ContentEvent event ) {
                notify( event );
        }
       
        public void retrieve( ContentEvent event ) {
                notify( event );
        }
       
        public void store( ContentEvent event ) {
                notify( event );
        }
         
        public void configure(Configuration configuration)
                        throws ConfigurationException {
                /*
                 * TODO: Configure the notification mechanism (http,
jms, javagroups)
                 */
        }
        
        public void notify( ContentEvent event ) {
                /*
                 * TODO: Modify this to actually send the event to the
other systems in a cluster.
                 * Maybe this should be subclassed to allow different
messaging implementations?
                 */
                Domain.log( "Called ContentModifiedNotifier.notify for "
+ event.getUri(), LOG_CHANNEL, Logger.DEBUG );
                if ( UriModifiedEvent.URIMODIFIED.isEnabled() ) {
                    EventDispatcher.getInstance().fireEvent(
                        UriModifiedEvent.URIMODIFIED, new
UriModifiedEvent(this, new Uri( event.getNamespace(), event.getUri()
)));
                } else {
                        Domain.log( "Can't notify, UriModifiedEvent is
disabled.", LOG_CHANNEL, Logger.DEBUG );
                }
        }
  
  }
  
  
  
  1.16      +34 -4    
jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java
  
  Index: ExtendedStore.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ExtendedStore.java        19 Jul 2004 12:39:42 -0000      1.15
  +++ ExtendedStore.java        22 Jul 2004 07:23:58 -0000      1.16
  @@ -393,6 +393,36 @@
                   txContentCacheSize, txContentCacheBytes,
maxByteSizePerEntry, noGlobalCacheInTx);
       }
       
  +    /**
  +     * Removes an object from all internal caches.
  +     * 
  +     * @param key the key under which the object is stored in the
caches.
  +     */
  +    public void removeObjectFromCache( Object key ) {
  +     getLogger().log( "Removing " + key + " from cache.",
  +             LOG_CHANNEL,
  +                     Logger.DEBUG );
  +     if ( contentStore.cacheResults() && contentCachingEnabled ) {
  +             contentCache.remove( key );
  +     }
  +     if ( nodeStore.cacheResults() ) {
  +             objectsCache.remove( key );
  +     }
  +     if ( securityStore.cacheResults() ) {
  +             permissionsCache.remove( key );
  +     }
  +     // Locks shouldn't be cached, but just in case.
  +     if ( lockStore.cacheResults() ) {
  +             locksCache.remove( key );
  +     }
  +     if ( revisionDescriptorsStore.cacheResults() ) {
  +             descriptorsCache.remove( key );
  +     }
  +     if ( revisionDescriptorStore.cacheResults() ) {
  +             descriptorCache.remove( key );
  +     }
  +    }
  +    
       public void exclusiveTransientLock(String uri)
                        throws ServiceAccessException {
                Xid txId = (Xid) activeTransactionBranch.get();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to