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.process.local;
016    
017    import com.liferay.portal.kernel.concurrent.AsyncBroker;
018    import com.liferay.portal.kernel.process.ProcessCallable;
019    
020    import java.io.Serializable;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public class ResponseProcessCallable<T extends Serializable>
026            implements ProcessCallable<Boolean> {
027    
028            public ResponseProcessCallable(long id, T result, Throwable throwable) {
029                    _id = id;
030                    _result = result;
031                    _throwable = throwable;
032            }
033    
034            @Override
035            public Boolean call() {
036                    AsyncBroker<Long, Serializable> asyncBroker =
037                            AsyncBrokerThreadLocal.getAsyncBroker();
038    
039                    if (_throwable != null) {
040                            return asyncBroker.takeWithException(_id, _throwable);
041                    }
042    
043                    return asyncBroker.takeWithResult(_id, _result);
044            }
045    
046            private static final long serialVersionUID = 1L;
047    
048            private final long _id;
049            private final T _result;
050            private final Throwable _throwable;
051    
052    }