001    /**
002     * Copyright (c) 2000-present 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.nio.intraband.proxy;
016    
017    import com.liferay.portal.kernel.executor.PortalExecutorManagerUtil;
018    import com.liferay.portal.kernel.io.Deserializer;
019    import com.liferay.portal.kernel.nio.intraband.Datagram;
020    import com.liferay.portal.kernel.nio.intraband.RegistrationReference;
021    
022    import java.util.concurrent.ExecutorService;
023    
024    /**
025     * @author Shuyang Zhou
026     */
027    public class AsyncIntrabandProxySkeleton implements IntrabandProxySkeleton {
028    
029            public static IntrabandProxySkeleton createAsyncIntrabandProxySkeleton(
030                    String skeletonId, IntrabandProxySkeleton intrabandProxySkeleton) {
031    
032                    ExecutorService executorService =
033                            PortalExecutorManagerUtil.getPortalExecutor(skeletonId, false);
034    
035                    if (executorService == null) {
036                            return intrabandProxySkeleton;
037                    }
038    
039                    return new AsyncIntrabandProxySkeleton(
040                            executorService, intrabandProxySkeleton);
041            }
042    
043            @Override
044            public void dispatch(
045                    final RegistrationReference registrationReference,
046                    final Datagram datagram, final Deserializer deserializer) {
047    
048                    _executorService.execute(
049                            new Runnable() {
050    
051                                    @Override
052                                    public void run() {
053                                            _intrabandProxySkeleton.dispatch(
054                                                    registrationReference, datagram, deserializer);
055                                    }
056    
057                            });
058            }
059    
060            private AsyncIntrabandProxySkeleton(
061                    ExecutorService executorService,
062                    IntrabandProxySkeleton intrabandProxySkeleton) {
063    
064                    _executorService = executorService;
065                    _intrabandProxySkeleton = intrabandProxySkeleton;
066            }
067    
068            private final ExecutorService _executorService;
069            private final IntrabandProxySkeleton _intrabandProxySkeleton;
070    
071    }