Java tutorial
/****************************************************************************** * Copyright(c) 2005-2007 SoftAMIS (http://www.soft-amis.com) * * All Rights Reserved. * * * * 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 com.zz.cluster4spring.registry.support.ex; import java.io.Serializable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; /** * Default implementation of * {@link com.zz.cluster4spring.registry.ConsumingRegistry}. It issues network * notifications when item for given key should be requested or given item * should be invalidated. To isolate details of network communication, it * delegates the actual details of network communication to corresponding * {@link CommunicationHelper}. In addition, it implements methods from * {@link RegistryEventProcessor} interface which allows this class to handle * notifications about item registrations/undregistration that are issued by * provider registry and also notifications about items invalidation which could * be issued by another ConsumerRegistries. * <p/> * The {@link CommunicationHelper} used by instance of this class is source for * events processed by RegistryEventProcessor. * * @author Andrew Sazonov * @version 1.0 * @see CommunicationHelper */ public class DefaultConsumingRegistry<K extends Serializable, V extends Serializable> extends com.zz.cluster4spring.registry.support.DefaultConsumingRegistry<K, V> implements InitializingBean, ApplicationListener { protected static final Log fLog = LogFactory.getLog(DefaultConsumingRegistry.class); public DefaultConsumingRegistry() { super(); } /** * Invoked by Spring and is used to check that CommunicationHelper is set. * * @throws Exception */ public void afterPropertiesSet() throws Exception { if (fLog.isDebugEnabled()) { fLog.debug("this run doInit parameters is null"); } doInit(); } @Override public void onApplicationEvent(ApplicationEvent aEvent) { try { if (aEvent instanceof ContextRefreshedEvent) { // doInit(); } if (aEvent instanceof ContextClosedEvent) { close(); } } catch (Exception e) { if (fLog.isErrorEnabled()) { fLog.error("Exception during processing application event. ", e); } } } }