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 java.util.Arrays;
018    
019    /**
020     * @author Shuyang Zhou
021     */
022    public class ThreadLocalDistributorRegistry {
023    
024            public static ThreadLocalDistributor[] getThreadLocalDistributors() {
025                    return _threadLocalDistributors;
026            }
027    
028            protected static int addThreadLocalDistributor(
029                    ThreadLocalDistributor threadLocalDistributor) {
030    
031                    int newLength = _threadLocalDistributors.length + 1;
032    
033                    ThreadLocalDistributor[] threadLocalDistributors = Arrays.copyOf(
034                            _threadLocalDistributors, newLength);
035    
036                    threadLocalDistributors[newLength - 1] = threadLocalDistributor;
037    
038                    _threadLocalDistributors = threadLocalDistributors;
039    
040                    return newLength - 1;
041            }
042    
043            protected static ThreadLocalDistributor getThreadLocalDistributor(
044                    int index) {
045    
046                    return _threadLocalDistributors[index];
047            }
048    
049            private static ThreadLocalDistributor[] _threadLocalDistributors =
050                    new ThreadLocalDistributor[0];
051    
052    }