001    /**
002     * Copyright (c) 2000-2013 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.security.pacl.DoPrivileged;
022    import com.liferay.portal.kernel.util.InstanceFactory;
023    import com.liferay.portal.kernel.util.PropsKeys;
024    
025    import java.util.Map;
026    import java.util.concurrent.ConcurrentHashMap;
027    
028    /**
029     * @author Alexander Chow
030     */
031    @DoPrivileged
032    public class LockListenerRegistryImpl implements LockListenerRegistry {
033    
034            public LockListenerRegistryImpl() {
035                    String[] lockListenerClassNames = PropsUtil.getArray(
036                            PropsKeys.LOCK_LISTENERS);
037    
038                    for (String lockListenerClassName : lockListenerClassNames) {
039                            try {
040                                    LockListener lockListener =
041                                            (LockListener)InstanceFactory.newInstance(
042                                                    lockListenerClassName);
043    
044                                    register(lockListener);
045                            }
046                            catch (Exception e) {
047                                    _log.error(e, e);
048                            }
049                    }
050            }
051    
052            @Override
053            public LockListener getLockListener(String className) {
054                    return _lockListeners.get(className);
055            }
056    
057            @Override
058            public void register(LockListener lockListener) {
059                    _lockListeners.put(lockListener.getClassName(), lockListener);
060            }
061    
062            @Override
063            public void unregister(LockListener lockListener) {
064                    _lockListeners.remove(lockListener.getClassName());
065            }
066    
067            private static Log _log = LogFactoryUtil.getLog(
068                    LockListenerRegistryImpl.class);
069    
070            private Map<String, LockListener> _lockListeners =
071                    new ConcurrentHashMap<String, LockListener>();
072    
073    }