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.kernel.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.util.transport.MulticastTransport;
020    
021    import java.lang.reflect.Field;
022    
023    /**
024     * @author Daniel Sanz
025     */
026    public class LicenseValidationTransportUtil {
027    
028            public static void stopMulticastTransportThread() {
029                    try {
030                            ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
031    
032                            Class licenseManagerClass = classLoader.loadClass(
033                                    "com.liferay.portal.license.LicenseManager");
034    
035                            Field[] fields = licenseManagerClass.getDeclaredFields();
036    
037                            for (Field field : fields) {
038                                    Class<?> type = field.getType();
039    
040                                    String typeName = type.getName();
041    
042                                    if (!typeName.equals(
043                                                    "com.liferay.util.transport.MulticastTransport")) {
044    
045                                            continue;
046                                    }
047    
048                                    field.setAccessible(true);
049    
050                                    try {
051                                            Object value = field.get(null);
052    
053                                            MulticastTransport multicastTransport =
054                                                    (MulticastTransport)value;
055    
056                                            if (multicastTransport != null) {
057                                                    multicastTransport.disconnect();
058                                            }
059                                    }
060                                    catch (IllegalAccessException iae) {
061                                            iae.printStackTrace();
062                                    }
063                                    finally {
064                                            field.setAccessible(false);
065                                    }
066                            }
067                    }
068                    catch (ClassNotFoundException cnfe) {
069                            if (_log.isDebugEnabled()) {
070                                    _log.debug(cnfe);
071                            }
072                    }
073            }
074    
075            private static Log _log = LogFactoryUtil.getLog(
076                    LicenseValidationTransportUtil.class);
077    
078    }