Author: jsorel Date: Wed Mar 7 15:29:08 2018 New Revision: 1826122 URL: http://svn.apache.org/viewvc?rev=1826122&view=rev Log: Resource : prepare listener API for Resources
Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeEvent.java sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeListener.java Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeEvent.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeEvent.java?rev=1826122&view=auto ============================================================================== --- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeEvent.java (added) +++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeEvent.java Wed Mar 7 15:29:08 2018 @@ -0,0 +1,39 @@ +/* + * 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.sis.storage; + +import java.util.EventObject; + +/** + * Parent class of all Resource events. + * + * @author Johann Sorel (Geomatys) + * @since 1.0 + * @module + */ +public abstract class ChangeEvent extends EventObject { + + /** + * Construct event. + * + * @param source The object on which the Event initially occurred. + */ + public ChangeEvent(Object source) { + super(source); + } + +} Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeListener.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeListener.java?rev=1826122&view=auto ============================================================================== --- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeListener.java (added) +++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ChangeListener.java Wed Mar 7 15:29:08 2018 @@ -0,0 +1,36 @@ +/* + * 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.sis.storage; + +/** + * Intercept event from a Resource. + * + * @author Johann Sorel (Geomatys) + * @param <T> + * @since 1.0 + * @module + */ +public interface ChangeListener<T extends ChangeEvent> { + + /** + * Method called when an ChangeEvent is produce by a Resource. + * + * @param event resource event, never null + */ + void changeOccured(T event); + +} Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java?rev=1826122&r1=1826121&r2=1826122&view=diff ============================================================================== --- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java [UTF-8] (original) +++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java [UTF-8] Wed Mar 7 15:29:08 2018 @@ -41,7 +41,7 @@ import org.opengis.metadata.Metadata; * </div> * * @author Johann Sorel (Geomatys) - * @version 0.8 + * @version 1.0 * * @see Aggregate#components() * @@ -103,4 +103,45 @@ public interface Resource { * @see DataStore#getMetadata() */ Metadata getMetadata() throws DataStoreException; + + /** + * Attaches a ChangeListener on the resource. + * The resource will call the {@link ChangeListener#changeOccured(org.apache.sis.storage.ChangeEvent) } + * method when a new event matching the predicate is produced. + * + * <p> + * The sample listener may be added multiple times with different predicates. + * Adding multiple times the same listener with the same predicate has no effect, + * The listener will only be called once per event. + * </p> + * + * <p> + * The resource is not required to keep a reference to the listener. + * For example the resource might discard a listener if the given predicate + * will never happen on this resource. + * </p> + * + * @param <T> type of {@linkplain ChangeEvent} + * @param listener listener to notify + * @param predicate class of {@linkplain ChangeEvent} to listen to, or null for all. + */ + //TODO : remove comment when implementated on all resources. + //<T extends ChangeEvent> void addListener(ChangeListener<? super T> listener, Class<T> predicate); + + /** + * Removes an attached ChangeListener from the resource. + * + * <p> + * Calling multiple times this method with the same listener or a listener + * which is unknown to this resource will have no effect and won't raise an + * exception. + * </p> + * + * @param <T> type of {@linkplain ChangeEvent} + * @param listener listener to remove + * @param predicate class of {@linkplain ChangeEvent} to listen to, or null for all. + */ + //TODO : remove comment when implementated on all resources. + //<T extends ChangeEvent> void removeListener(ChangeListener<? super T> listener, Class<T> predicate); + }