001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.management.domain.handler.base;
022
023 import org.apache.qpid.management.domain.model.type.Binary;
024 import org.apache.qpid.transport.codec.Decoder;
025
026 /**
027 * Base class for content indication message handlers.
028 *
029 * @author Andrea Gazzarini
030 */
031 public abstract class ContentIndicationMessageHandler extends BaseMessageHandler
032 {
033 /**
034 * Processes the income message.
035 *
036 * @param decoder the decoder used to parse the message.
037 * @param sequenceNumber the sequence number of the message.
038 */
039 public final void process (Decoder decoder, int sequenceNumber)
040 {
041 String packageName = decoder.readStr8();
042 String className = decoder.readStr8();
043 Binary classHash = new Binary(decoder.readBin128());
044
045 long timeStampOfCurrentSample = decoder.readDatetime();
046 long timeObjectWasCreated = decoder.readDatetime();
047 long timeObjectWasDeleted = decoder.readDatetime();
048
049 Binary objectId = new Binary(decoder.readBin128());
050
051 if (objectHasBeenRemoved(timeObjectWasDeleted, timeStampOfCurrentSample))
052 {
053 removeObjectInstance(packageName,className,classHash,objectId);
054 } else
055 {
056 updateDomainModel(
057 packageName,
058 className,
059 classHash,
060 objectId,
061 timeStampOfCurrentSample,
062 timeObjectWasCreated,
063 timeObjectWasDeleted,
064 decoder.readReaminingBytes());
065 }
066 }
067
068 /**
069 * Removes an object instance from the domain model.
070 *
071 * @param packageName the package name.
072 * @param className the class name.
073 * @param classHash the class hash.
074 * @param objectId the object identifier.
075 */
076 void removeObjectInstance(String packageName, String className,Binary classHash, Binary objectId)
077 {
078 _domainModel.removeObjectInstance(packageName,className,classHash,objectId);
079 }
080
081 /**
082 * Checks if the timestamps contained in the message indicate that the object has been removed.
083 *
084 * @param deletionTimestamp time object was deleted.
085 * @param now timestamp of the current message.
086 * @return true if the object has been removed, false otherwise.
087 */
088 boolean objectHasBeenRemoved(long deletionTimestamp, long now) {
089 return (deletionTimestamp != 0) && (now > deletionTimestamp);
090 }
091
092 /**
093 * Updates domain model with the incoming data.
094 * This is a template method that each concrete subclass must implement in order to update the domain model
095 * with the incoming data.
096 *
097 * @param packageName the name of the package.
098 * @param className the name of the class.
099 * @param objectId the object identifier.
100 * @param timeStampOfCurrentSample timestamp of current sample.
101 * @param timeObjectWasCreated time object was created.
102 * @param timeObjectWasDeleted time object was deleted.
103 * @param contentData object instance incoming data.
104 */
105 protected abstract void updateDomainModel(
106 String packageName,
107 String className,
108 Binary classHash,
109 Binary objectId,
110 long timeStampOfCurrentSample,
111 long timeObjectWasCreated,
112 long timeObjectWasDeleted,
113 byte []contentData );
114 }
|