001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.util;
016    
017    import com.liferay.portal.kernel.lock.LockListener;
018    import com.liferay.portal.kernel.lock.LockListenerRegistry;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.InstanceFactory;
022    import com.liferay.portal.kernel.util.PropsKeys;
023    
024    import java.util.Map;
025    import java.util.concurrent.ConcurrentHashMap;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class LockListenerRegistryImpl implements LockListenerRegistry {
031    
032            public LockListenerRegistryImpl() {
033                    String[] lockListenerClassNames = PropsUtil.getArray(
034                            PropsKeys.LOCK_LISTENERS);
035    
036                    for (String lockListenerClassName : lockListenerClassNames) {
037                            try {
038                                    LockListener lockListener =
039                                            (LockListener)InstanceFactory.newInstance(
040                                                    lockListenerClassName);
041    
042                                    register(lockListener);
043                            }
044                            catch (Exception e) {
045                                    _log.error(e, e);
046                            }
047                    }
048            }
049    
050            public LockListener getLockListener(String className) {
051                    return _lockListeners.get(className);
052            }
053    
054            public void register(LockListener lockListener) {
055                    _lockListeners.put(lockListener.getClassName(), lockListener);
056            }
057    
058            public void unregister(LockListener lockListener) {
059                    _lockListeners.remove(lockListener.getClassName());
060            }
061    
062            private static Log _log = LogFactoryUtil.getLog(
063                    LockListenerRegistryImpl.class);
064    
065            private Map<String, LockListener> _lockListeners =
066                    new ConcurrentHashMap<String, LockListener>();
067    
068    }