You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Gaurav Handa <gh...@quark.co.in> on 2004/07/23 13:30:14 UTC

RE: cvs commit: jakarta-slide/src/share/org/apache/slide/store Ex tendedStore.java

Hi james

 I am new to slide. can u help me a bit in writing Slide stores. I am unable
to understand the values in domain.xml.
 

Regards,
Gaurav Handa
9281


-----Original Message-----
From: James Mason [mailto:masonjm@ah.org]
Sent: Thursday, July 22, 2004 9:16 PM
To: slide-dev@jakarta.apache.org
Subject: Re: cvs commit: jakarta-slide/src/share/org/apache/slide/store
ExtendedStore.java


This sounds like a good approach to me. I'll have a look at the classes
you mentioned.

-James

>>> dflorey@apache.org 07/22/04 12:52 AM >>>
Hi James,
I've looked a little deeper in your code and there are some suggestions 
I'd like to make:
To minimize the notification traffic I'd give the advice to use the 
EventCollectionFilter stuff. All events that occur in a single 
transaction can be collected by using EventCollections. These 
collections can be filtered so that you can send only the relevant 
changes to all nodes in the cluster.
What about introducing a new method in the EventCollecitonFilter 
(something like getModifiedUris()). This method can remove redundant 
events that often occur in the Slide kernel when using webdav methods.
So what needs to be done is to write an event collection listener (have 
a look at org.apache.slide.search.IndexTrigger as an example). The 
collection listener can be informed synchronously or asynchronously so 
that Slide can get optimized for speed or immediate sync.
In this listener the collection needs to be filtered by the new 
getModifiedUris() method. After collecting them you can throw a new 
UrisModifiedEvent and send include the changed uris by implementing the 
RemoteInformation interface.
This all might sound a little complicated but I promise it will work 
fine and you will get all the benefits of the existing code...
Regards,
Daniel

James Mason schrieb:

>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
>
>  
>
>>>>masonjm@apache.org 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:masonjm@apache.org">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:masonjm@apache.org">James Mason</a>
>   */
>  public interface UriModifiedListener extends EventListener {
>  	
>  	public void modified( UriModifiedEvent event );
>  
>  }
>  
>  
>  
>  1.1                 
>jakarta-slide/src/share/org/apache/slide/event/UncacheModifiedUriListener.j
ava
>  
>  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:masonjm@apache.org">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:masonjm@apache.org">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: slide-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: slide-dev-help@jakarta.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: slide-dev-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org