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.nio.intraband.messaging;
016    
017    import com.liferay.portal.kernel.messaging.Destination;
018    import com.liferay.portal.kernel.messaging.MessageBus;
019    import com.liferay.portal.kernel.messaging.MessageBusUtil;
020    import com.liferay.portal.kernel.process.ProcessCallable;
021    import com.liferay.portal.kernel.process.ProcessException;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    public class DestinationConfigurationProcessCallable
027            implements ProcessCallable<Boolean> {
028    
029            public DestinationConfigurationProcessCallable(String destinationName) {
030                    _destinationName = destinationName;
031            }
032    
033            @Override
034            public Boolean call() throws ProcessException {
035                    MessageBus messageBus = MessageBusUtil.getMessageBus();
036    
037                    Destination destination = messageBus.getDestination(_destinationName);
038    
039                    if (destination == null) {
040                            throw new ProcessException("No such destination " + destination);
041                    }
042    
043                    if (destination instanceof IntrabandBridgeDestination) {
044                            return Boolean.FALSE;
045                    }
046    
047                    IntrabandBridgeDestination intrabandBridgeDestination =
048                            new IntrabandBridgeDestination(destination);
049    
050                    messageBus.addDestination(intrabandBridgeDestination);
051    
052                    return Boolean.TRUE;
053            }
054    
055            private static final long serialVersionUID = 1L;
056    
057            private String _destinationName;
058    
059    }