001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.command;
018
019import org.apache.activemq.state.CommandVisitor;
020
021/**
022 * 
023 * @openwire:marshaller code="6"
024 * 
025 */
026public class ProducerInfo extends BaseCommand {
027
028    public static final byte DATA_STRUCTURE_TYPE = CommandTypes.PRODUCER_INFO;
029
030    protected ProducerId producerId;
031    protected ActiveMQDestination destination;
032    protected BrokerId[] brokerPath;
033    protected boolean dispatchAsync;
034    protected int windowSize;
035
036    public ProducerInfo() {
037    }
038
039    public ProducerInfo(ProducerId producerId) {
040        this.producerId = producerId;
041    }
042
043    public ProducerInfo(SessionInfo sessionInfo, long producerId) {
044        this.producerId = new ProducerId(sessionInfo.getSessionId(), producerId);
045    }
046
047    public ProducerInfo copy() {
048        ProducerInfo info = new ProducerInfo();
049        copy(info);
050        return info;
051    }
052
053    public void copy(ProducerInfo info) {
054        super.copy(info);
055        info.producerId = producerId;
056        info.destination = destination;
057    }
058
059    public byte getDataStructureType() {
060        return DATA_STRUCTURE_TYPE;
061    }
062
063    /**
064     * @openwire:property version=1 cache=true
065     */
066    public ProducerId getProducerId() {
067        return producerId;
068    }
069
070    public void setProducerId(ProducerId producerId) {
071        this.producerId = producerId;
072    }
073
074    /**
075     * @openwire:property version=1 cache=true
076     */
077    public ActiveMQDestination getDestination() {
078        return destination;
079    }
080
081    public void setDestination(ActiveMQDestination destination) {
082        this.destination = destination;
083    }
084
085    public RemoveInfo createRemoveCommand() {
086        RemoveInfo command = new RemoveInfo(getProducerId());
087        command.setResponseRequired(isResponseRequired());
088        return command;
089    }
090
091    /**
092     * The route of brokers the command has moved through.
093     * 
094     * @openwire:property version=1 cache=true
095     */
096    public BrokerId[] getBrokerPath() {
097        return brokerPath;
098    }
099
100    public void setBrokerPath(BrokerId[] brokerPath) {
101        this.brokerPath = brokerPath;
102    }
103
104    public Response visit(CommandVisitor visitor) throws Exception {
105        return visitor.processAddProducer(this);
106    }
107
108    /**
109     * If the broker should dispatch messages from this producer async. Since
110     * sync dispatch could potentally block the producer thread, this could be
111     * an important setting for the producer.
112     * 
113     * @openwire:property version=2
114     */
115    public boolean isDispatchAsync() {
116        return dispatchAsync;
117    }
118
119    public void setDispatchAsync(boolean dispatchAsync) {
120        this.dispatchAsync = dispatchAsync;
121    }
122
123    /**
124     * Used to configure the producer window size. A producer will send up to
125     * the configured window size worth of payload data to the broker before
126     * waiting for an Ack that allows him to send more.
127     * 
128     * @openwire:property version=3
129     */
130    public int getWindowSize() {
131        return windowSize;
132    }
133
134    public void setWindowSize(int windowSize) {
135        this.windowSize = windowSize;
136    }
137
138}