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 */
017 package org.apache.servicemix.jbi.messaging;
018
019 import java.io.IOException;
020 import java.io.ObjectInput;
021
022 import javax.jbi.messaging.InOut;
023
024 /**
025 * InOut message exchange.
026 *
027 * @version $Revision: 564607 $
028 */
029 public class InOutImpl extends MessageExchangeImpl implements InOut {
030
031 private static final long serialVersionUID = -1639492357707831113L;
032
033 private static final int[][] STATES_CONSUMER = {
034 {CAN_CONSUMER + CAN_OWNER + CAN_SET_IN_MSG + CAN_SEND + CAN_STATUS_ACTIVE, 1, -1, -1, -1 },
035 {CAN_CONSUMER, 2, 2, 3, 3 },
036 {CAN_CONSUMER + CAN_OWNER + CAN_SEND + CAN_STATUS_ERROR + CAN_STATUS_DONE, -1, -1, 4, 4 },
037 {CAN_CONSUMER + CAN_OWNER, -1, -1, -1, -1 },
038 {CAN_CONSUMER, -1, -1, -1, -1 }
039 };
040
041 private static final int[][] STATES_PROVIDER = {
042 {CAN_PROVIDER, 1, -1, -1 },
043 {CAN_PROVIDER + CAN_OWNER + CAN_SET_OUT_MSG + CAN_SET_FAULT_MSG + CAN_SEND
044 + CAN_STATUS_ACTIVE + CAN_STATUS_ERROR, 2, 2, 3, -1 },
045 {CAN_PROVIDER, -1, -1, 4, 4 },
046 {CAN_PROVIDER, -1, -1, -1, -1 },
047 {CAN_PROVIDER + CAN_OWNER, -1, -1, -1, -1 }
048 };
049
050 public InOutImpl() {
051 }
052
053 public InOutImpl(String exchangeId) {
054 super(exchangeId, MessageExchangeSupport.IN_OUT, STATES_CONSUMER);
055 this.mirror = new InOutImpl(this);
056 }
057
058 public InOutImpl(ExchangePacket packet) {
059 super(packet, STATES_CONSUMER);
060 this.mirror = new InOutImpl(this);
061 }
062
063 protected InOutImpl(InOutImpl mep) {
064 super(mep.packet, STATES_PROVIDER);
065 this.mirror = mep;
066 }
067
068 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
069 this.packet = new ExchangePacket();
070 this.packet.readExternal(in);
071 if (this.packet.in != null) {
072 this.packet.in.exchange = this;
073 }
074 if (this.packet.out != null) {
075 this.packet.out.exchange = this;
076 }
077 if (this.packet.fault != null) {
078 this.packet.fault.exchange = this;
079 }
080 this.state = in.read();
081 this.mirror = new InOutImpl();
082 this.mirror.mirror = this;
083 this.mirror.packet = this.packet;
084 this.mirror.state = in.read();
085 boolean provider = in.readBoolean();
086 if (provider) {
087 this.states = STATES_PROVIDER;
088 this.mirror.states = STATES_CONSUMER;
089 } else {
090 this.states = STATES_CONSUMER;
091 this.mirror.states = STATES_PROVIDER;
092 }
093 }
094
095 }