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.activemq.kaha;
018
019 import java.io.Externalizable;
020 import java.io.IOException;
021 import java.io.ObjectInput;
022 import java.io.ObjectOutput;
023
024 import org.apache.activemq.util.IOHelper;
025
026 /**
027 * Used by RootContainers
028 *
029 *
030 */
031 public class ContainerId implements Externalizable {
032 private static final long serialVersionUID = -8883779541021821943L;
033 private Object key;
034 private String dataContainerName;
035
036 public ContainerId() {
037 }
038
039 public ContainerId(Object key, String dataContainerName) {
040 this.key = key;
041 this.dataContainerName = dataContainerName;
042 }
043
044 /**
045 * @return Returns the dataContainerPrefix.
046 */
047 public String getDataContainerName() {
048 return dataContainerName;
049 }
050
051 /**
052 * @return Returns the key.
053 */
054 public Object getKey() {
055 return key;
056 }
057
058 public int hashCode() {
059 return key.hashCode() ^ dataContainerName.hashCode();
060 }
061
062 public boolean equals(Object obj) {
063 if (obj == null || obj.getClass() != ContainerId.class) {
064 return false;
065 }
066 ContainerId other = (ContainerId)obj;
067 return other.key.equals(this.key) && other.dataContainerName.equals(this.dataContainerName);
068 }
069
070 public void writeExternal(ObjectOutput out) throws IOException {
071 out.writeUTF(getDataContainerName());
072 out.writeObject(key);
073 }
074
075 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
076 dataContainerName = in.readUTF();
077 key = in.readObject();
078 }
079
080 public String toString() {
081 return "CID{" + dataContainerName + ":" + key + "}";
082 }
083 }