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 ProvidingRegistry. It issues network notifications * when item is registered and unregistered, but 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 requests for items that are published by * this provider registry. The CommunicationHelper used by instance of this * class is source for events processed by RegistryEventProcessor. * * @author Andrew Sazonov * @version 1.0 * @see CommunicationHelper */ public class DefaultProvidingRegistry<K extends Serializable, V extends Serializable> extends com.zz.cluster4spring.registry.support.DefaultProvidingRegistry<K, V> implements InitializingBean, ApplicationListener { protected static final Log fLog = LogFactory.getLog(DefaultProvidingRegistry.class); public DefaultProvidingRegistry() { super(); } /** * Invoked by Spring and performs checking that CommunicationHelper was * actually set. * * @throws Exception */ @SuppressWarnings({ "ProhibitedExceptionDeclared" }) public void afterPropertiesSet() throws Exception { } 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); } } } }