summaryrefslogtreecommitdiff
path: root/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java
blob: 99916085d6d857632b96a73c676a6c5100f216c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.management.messages;

import org.apache.qpid.management.Messages;
import org.apache.qpid.management.Names;
import org.apache.qpid.management.Protocol;
import org.apache.qpid.management.configuration.Configuration;
import org.apache.qpid.management.domain.model.QpidMethod;
import org.apache.qpid.management.domain.model.type.Binary;
import org.apache.qpid.transport.DeliveryProperties;
import org.apache.qpid.transport.Header;
import org.apache.qpid.transport.MessageProperties;
import org.apache.qpid.transport.ReplyTo;
import org.apache.qpid.transport.util.Logger;

/**
 * Abstract representation of a method invocation request message.
 * Concrete subclasses must supply the values needed to build & encode the message.
 * 
 * @author Andrea Gazzarini
 */
public abstract class MethodInvocationRequestMessage extends ManagementMessage
{
	private final static Logger LOGGER = Logger.get(MethodInvocationRequestMessage.class);
	
	private DeliveryProperties _deliveryProperties;
	private MessageProperties _messageProperties;
	private Header _header;	
	
	/**
	 * Builds a new method invocation request message with the given target identifiers.
	 * 
	 * @param bankId the bank identifier.
	 * @param brokerId the broker identifier.
	 */
	public MethodInvocationRequestMessage(long bankId, long brokerId) 
	{
		 ReplyTo replyTo=new ReplyTo();
	     replyTo.setRoutingKey(Configuration.getInstance().getMethodReplyQueueName());
	     _messageProperties = new MessageProperties();
	     _messageProperties.setReplyTo(replyTo);

	     String routingKey = String.format(Names.AGENT_ROUTING_KEY_PREFIX+"%s.%s", brokerId,bankId);
	     
	     LOGGER.debug(Messages.QMAN_200032_COMMAND_MESSAGE_ROUTING_KEY, routingKey);
	     
	     _deliveryProperties = new DeliveryProperties();	     
	     _deliveryProperties.setRoutingKey(routingKey);        
	     _header = new Header(_deliveryProperties, _messageProperties);
	}
	
    @Override
    char opcode ()
    {
        return Protocol.OPERATION_INVOCATION_REQUEST_OPCODE;
    }

    /**
     * Returns the package name.
     * 
     * @return the package name.
     */
    protected abstract String packageName();
    
    /**
     * Returns the class name.
     * 
     * @return the class name.
     */
    protected abstract String className();
    
    /**
     * Returns the schema hash.
     * 
     * @return the schema hash.
     */
    protected abstract Binary schemaHash();
    
    /**
     * Returns the object identifier.
     * 
     * @return the object identifier.
     */
    protected abstract Binary objectId();
    
    /**
     * Returns the method to be invoked.
     * 
     * @return the method to be invoked.
     */
    protected abstract QpidMethod method();
    
    /**
     * Returns the parameters used for method invocation.
     * 
     * @return the parameters used for method invocation.
     */
    protected abstract Object[] parameters();

    /**
     * Returns the delivery properties of this message.
     * 
     * @return the delivery properties of this message.
     */
    public DeliveryProperties getDeliveryProperties ()
    {
        return _deliveryProperties;
    }

    /**
     * Returns the header of this message.
     * 
     * @return the header of this message.
     */
    public Header getHeader ()
    {
        return _header;
    }

    /**
     * Returns the messages header properties of this message.
     * 
     * @return the message header properties of this message.
     */
    public MessageProperties getMessageProperties ()
    {
        return _messageProperties;
    }
    
    @Override
    void specificMessageEncoding ()
    {
        objectId().encode(_codec);
        _codec.writeStr8(packageName());
        _codec.writeStr8(className());        
        schemaHash().encode(_codec);
        
        QpidMethod method = method();
        _codec.writeStr8(method.getName());
       method.encodeParameters(parameters(), _codec);
    }
}