You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by me...@cs.man.ac.uk on 2008/07/07 11:10:51 UTC

Schema Request

Hello Ted/Anybody,

Could you please correct me about the schema request (AM1S) which I am 
sending to broker to get the schema response for particular class?

Could you please let me know what is wrong here. I think schema request is 
not healthy. Please guide me here. I am not receiving the schema response 
with this schema request

Here is the code snippet of Schema request and Schema response.
// Code snippet for Schema Request (AM1S)
....

p.opcode="AM1S";
p.sequenceNo=500;
p.packageName="qpid";
p.classname="vhost";

message.clear();
try {
// encode the opcode
message.put(p.opcode.getBytes("UTF-8"));
message.putInt( p.sequenceNo);
// encode the package name
encoder.writeStr8(p.packageName);
message.putShort((byte) p.packageName.length());
message.put(p.packageName.getBytes("UTF-8"));
// encode the class name
encoder.writeStr8(p.classname);
message.putShort((byte) p.classname.length());
message.put(p.classname.getBytes("UTF-8"));
// encode the schema hash
// *** schema has contents which it got from 
// byte[] schemaHash=decoder.readBin128(); something like [B@2bb514  ***

encoder.writeBin128(schemaHash);
message.put((byte) schemaHash.length);
message.put(schemaHash);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
........
........

------

//Start Code snippet Schema Response (AM1s)

String packname = decoder.readStr8();
System.out.println("Package Name: " + packname);
String clasnam = decoder.readStr8();
System.out.println("Class Name: " + clasnam);
				
// get the decoded schema hash
decoder.readBin128();
// get the decoded properties contents
int propCnt = decoder.readUint16();
System.out.println("Property content:   " + propCnt);
long statCnt = decoder.readUint16();
System.out.println("Statistic content:   " + statCnt);
int methodCnt = decoder.readUint16();
System.out.println("Method content:   " + methodCnt);
int eventCnt = decoder.readUint16();
System.out.println("Event content:   " + eventCnt);
	
for( int i = 0; i < propCnt; i++ )
{	// decode the MAP
Map<String,Object> map = decoder.readMap();
}
				
for( int i = 0; i < statCnt; i++ )
{
// decode the MAP
Map<String,Object> map = decoder.readMap();
}
				
for( int i = 0; i < methodCnt; i++ )
{	// decode the MAP
Map<String,Object> map = decoder.readMap();
}
				
for( int i = 0; i < eventCnt; i++ )
{	// decode the MAP
Map<String,Object> map = decoder.readMap();
}
				    
---------
End of the Code

Thank you.

Best Regards,
Rahul


Re: Schema Request

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> On Jul 11 2008, Ted Ross wrote:
>
>> mehtar@cs.man.ac.uk wrote:
>> > Hello Ted,
>> >
>> > Yes, this method works for the encoding of schema hash in the 
>> Schema > Request (AM1S).
>> >
>> > Now I am able to fetch the Schema for the desired class. I have > 
>> another question in the format of this schema. You can see it at the 
>> > end of this email (output from the Management Client)… Also 
>> attached > the output.text with this email.
>> >
>> > 1. Is this format correct? Am I printing the Schema-hash (from the 
>> > schema request correctly)
>> >
>> > For example, I am doubtful about access, index, type… I am getting 
>> > their corresponding numeric values here…
>> Rahul,
>>
>> You have parsed most of the schema data correctly. The only problem I 
>> see with your code is that it doesn't handle method arguments. When 
>> you decode the map for a method, you need to get the argument count 
>> and decode maps for each argument.
>>
>> The "index" field is boolean (0=false, 1=true), the meanings for the 
>> numeric values for "access" and "type" are documented on the wiki 
>> page 
>> (http://cwiki.apache.org/confluence/display/qpid/Management+Design+notes). 
>>
>>
>> -Ted
>>
>>
>
> Hi Ted,
>
> Thanks very much for your qpick reply.
>
> So if you see the schema for class "broker" in the attached output.txt 
> file in the previous email. For the method name = joinCluster. it does 
> the same thing you suggested for, get the argument count (in this case 
> 1) and decode it (i see the argument name = clusterName, type =6, dir= 
> I, in this case). So it means it handles the method argument... are 
> you pointing the same thing for?
>
> Thank you.
>
> Best Regards,
> Rahul
>
Rahul,

I was referring to your code, which does not take into account the 
argument count for methods.

The output file (which is hard to read because you do not delimit the 
maps) shows the map for the argument to "joinCluster" but does not show 
the arguments for the "echo" method. In other words, there are maps in 
the response that you did not print out because your counts don't 
include the method arguments.

-Ted


Re: Schema Request

Posted by me...@cs.man.ac.uk.
On Jul 11 2008, Ted Ross wrote:

> mehtar@cs.man.ac.uk wrote:
> > Hello Ted,
> >
> > Yes, this method works for the encoding of schema hash in the Schema 
> > Request (AM1S).
> >
> > Now I am able to fetch the Schema for the desired class. I have 
> > another question in the format of this schema. You can see it at the 
> > end of this email (output from the Management Client)… Also attached 
> > the output.text with this email.
> >
> > 1. Is this format correct? Am I printing the Schema-hash (from the 
> > schema request correctly)
> >
> > For example, I am doubtful about access, index, type… I am getting 
> > their corresponding numeric values here…
> Rahul,
> 
> You have parsed most of the schema data correctly. The only problem I 
> see with your code is that it doesn't handle method arguments. When you 
> decode the map for a method, you need to get the argument count and 
> decode maps for each argument.
> 
> The "index" field is boolean (0=false, 1=true), the meanings for the 
> numeric values for "access" and "type" are documented on the wiki page 
> (http://cwiki.apache.org/confluence/display/qpid/Management+Design+notes).
> 
> -Ted
> 
> 

Hi Ted,

Thanks very much for your qpick reply.

So if you see the schema for class "broker" in the attached output.txt file 
in the previous email. For the method name = joinCluster. it does the same 
thing you suggested for, get the argument count (in this case 1) and decode 
it (i see the argument name = clusterName, type =6, dir= I, in this case). 
So it means it handles the method argument... are you pointing the same 
thing for?

Thank you.

Best Regards,
Rahul


Re: Schema Request

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> Hello Ted,
>
> Yes, this method works for the encoding of schema hash in the Schema 
> Request (AM1S).
>
> Now I am able to fetch the Schema for the desired class. I have 
> another question in the format of this schema. You can see it at the 
> end of this email (output from the Management Client)… Also attached 
> the output.text with this email.
>
> 1. Is this format correct? Am I printing the Schema-hash (from the 
> schema request correctly)
>
> For example, I am doubtful about access, index, type… I am getting 
> their corresponding numeric values here…
Rahul,

You have parsed most of the schema data correctly. The only problem I 
see with your code is that it doesn't handle method arguments. When you 
decode the map for a method, you need to get the argument count and 
decode maps for each argument.

The "index" field is boolean (0=false, 1=true), the meanings for the 
numeric values for "access" and "type" are documented on the wiki page 
(http://cwiki.apache.org/confluence/display/qpid/Management+Design+notes).

-Ted


Re: Schema Request

Posted by me...@cs.man.ac.uk.
Hello Ted,

Yes, this method works for the encoding of schema hash in the Schema 
Request (AM1S).

Now I am able to fetch the Schema for the desired class. I have another 
question in the format of this schema. You can see it at the end of this 
email (output from the Management Client)… Also attached the output.text 
with this email.

1. Is this format correct? Am I printing the Schema-hash (from the schema 
request correctly)

For example, I am doubtful about access, index, type… I am getting their 
corresponding numeric values here…

And here is the code snippet for retrieving schema Response…

Start of code snippet
-----------
case 's':

		String packagename = decoder.readStr8();
		System.out.println("Package Name: " + packagename);
		String clasnam = decoder.readStr8();
		System.out.println("Class Name: " + clasnam);

		// decode the schema hash
		decoder.readBin128();
		// get the decoded properties contents
		int propCnt = decoder.readUint16();
		System.out.println("Property content:   " + propCnt);
		long statCnt = decoder.readUint16();
		System.out.println("Statistic content:   " + statCnt);
		int methodCnt = decoder.readUint16();
		System.out.println("Method content:   " + methodCnt);
		int eventCnt = decoder.readUint16();
		System.out.println("Event content:   " + eventCnt);

		for( int i = 0; i < propCnt; i++ )
		{	// decode the MAP
			Map<String,Object> map = decoder.readMap();
			printMap(map);
		}

		for( int i = 0; i < statCnt; i++ )
		{	// decode the MAP
			Map<String,Object> map = decoder.readMap();
			printMap(map);
		}
		for( int i = 0; i < methodCnt; i++ )
		{	// decode the MAP
			Map<String,Object> map = decoder.readMap();
			printMap(map);
		}

		for( int i = 0; i < eventCnt; i++ )
		{	// decode the MAP
			Map<String,Object> map = decoder.readMap();
			printMap(map);
		}
		break;
		}

		}catch(Exception e)
		{
			System.out.print("Error reading message");
			e.printStackTrace();
		}
	}

	/*
	 * print the decoded map
	 * TODO: fix the warning and comment it when it works
	 */

	public void printMap(Map<String,Object> mapnew)
	{
		Set s=mapnew.entrySet();
		Iterator it=s.iterator();
		for (Iterator iterator = s.iterator(); iterator.hasNext();) 
		{
			Object object = (Object) iterator.next();
			System.out.println(object.toString());
		}
	}
-------------
End of the code snippet


2. how can I invoke the method for a particular class (meaning method 
request AM1M) ?

---------------------------------

-----------
Management Client Output (FOR QUESTION 1.)
-----------

	  *******    MENU   *************
#########################################################

1. Broker Query Request
2. Package Query Request
3. Class Query Request
4. Schema Query Request
5. Method Request
0. Exit

#########################################################
Please Enter your choice for REQUEST
4
*************************

1. agent
2. binding
3. bridge
4. broker
5. client
6. consumer
7. destination
8. exchange
9. link
10. producer
11. queue
12. session
13. system
14. vhost

*************************
Enter the class name (in small letters) for which you need SCHEMA
system
Query Schema Request Sent...


A
M
1
s
Sequence No: 444
Package Name: qpid
Class Name: system
Property content:   6
Statistic content:   0
Method content:   0
Event content:   0
access=1
index=1
name=sysId
type=14
access=3
desc=Operating System Name
index=0
name=osName
type=6
access=3
desc=Node Name
index=0
name=nodeName
type=6
access=3
index=0
name=release
type=6
access=3
index=0
name=version
type=6
access=3
index=0
name=machine
type=6
	  *******    MENU   *************
#########################################################

1. Broker Query Request
2. Package Query Request
3. Class Query Request
4. Schema Query Request
5. Method Request
0. Exit

#########################################################
Please Enter your choice for REQUEST
4
*************************

1. agent
2. binding
3. bridge
4. broker
5. client
6. consumer
7. destination
8. exchange
9. link
10. producer
11. queue
12. session
13. system
14. vhost

*************************
Enter the class name (in small letters) for which you need SCHEMA
queue
Query Schema Request Sent...


A
M
1
s
Sequence No: 444
Package Name: qpid
Class Name: queue
Property content:   7
Statistic content:   43
Method content:   1
Event content:   0
access=1
index=1
name=vhostRef
type=10
access=1
index=1
name=name
type=6
access=1
index=0
name=durable
type=11
access=1
index=0
name=autoDelete
type=11
access=1
index=0
name=exclusive
type=11
access=3
desc=Arguments supplied in queue.declare
index=0
name=arguments
type=15
access=3
desc=Reference to persistent queue (if durable)
index=0
name=storeRef
type=10
desc=Total messages enqueued
name=msgTotalEnqueues
type=4
unit=message
desc=Total messages dequeued
name=msgTotalDequeues
type=4
unit=message
desc=Transactional messages enqueued
name=msgTxnEnqueues
type=4
unit=message
desc=Transactional messages dequeued
name=msgTxnDequeues
type=4
unit=message
desc=Persistent messages enqueued
name=msgPersistEnqueues
type=4
unit=message
desc=Persistent messages dequeued
name=msgPersistDequeues
type=4
unit=message
desc=Current size of queue in messages
name=msgDepth
type=3
unit=message
desc=Current size of queue in messages (High)
name=msgDepthHigh
type=3
unit=message
desc=Current size of queue in messages (Low)
name=msgDepthLow
type=3
unit=message
desc=Total messages enqueued
name=byteTotalEnqueues
type=4
unit=octet
desc=Total messages dequeued
name=byteTotalDequeues
type=4
unit=octet
desc=Transactional messages enqueued
name=byteTxnEnqueues
type=4
unit=octet
desc=Transactional messages dequeued
name=byteTxnDequeues
type=4
unit=octet
desc=Persistent messages enqueued
name=bytePersistEnqueues
type=4
unit=octet
desc=Persistent messages dequeued
name=bytePersistDequeues
type=4
unit=octet
desc=Current size of queue in bytes
name=byteDepth
type=3
unit=octet
desc=Current size of queue in bytes (High)
name=byteDepthHigh
type=3
unit=octet
desc=Current size of queue in bytes (Low)
name=byteDepthLow
type=3
unit=octet
desc=Total enqueue transactions started 
name=enqueueTxnStarts
type=4
unit=transaction
desc=Total enqueue transactions committed
name=enqueueTxnCommits
type=4
unit=transaction
desc=Total enqueue transactions rejected
name=enqueueTxnRejects
type=4
unit=transaction
desc=Current pending enqueue transactions
name=enqueueTxnCount
type=3
unit=transaction
desc=Current pending enqueue transactions (High)
name=enqueueTxnCountHigh
type=3
unit=transaction
desc=Current pending enqueue transactions (Low)
name=enqueueTxnCountLow
type=3
unit=transaction
desc=Total dequeue transactions started
name=dequeueTxnStarts
type=4
unit=transaction
desc=Total dequeue transactions committed
name=dequeueTxnCommits
type=4
unit=transaction
desc=Total dequeue transactions rejected
name=dequeueTxnRejects
type=4
unit=transaction
desc=Current pending dequeue transactions
name=dequeueTxnCount
type=3
unit=transaction
desc=Current pending dequeue transactions (High)
name=dequeueTxnCountHigh
type=3
unit=transaction
desc=Current pending dequeue transactions (Low)
name=dequeueTxnCountLow
type=3
unit=transaction
desc=Current consumers on queue
name=consumers
type=3
unit=consumer
desc=Current consumers on queue (High)
name=consumersHigh
type=3
unit=consumer
desc=Current consumers on queue (Low)
name=consumersLow
type=3
unit=consumer
desc=Current bindings
name=bindings
type=3
unit=binding
desc=Current bindings (High)
name=bindingsHigh
type=3
unit=binding
desc=Current bindings (Low)
name=bindingsLow
type=3
unit=binding
desc=Messages consumed but not yet acked
name=unackedMessages
type=3
unit=message
desc=Messages consumed but not yet acked (High)
name=unackedMessagesHigh
type=3
unit=message
desc=Messages consumed but not yet acked (Low)
name=unackedMessagesLow
type=3
unit=message
desc=Broker latency through this queue (Samples)
name=messageLatencySamples
type=9
unit=nanosecond
desc=Broker latency through this queue (Min)
name=messageLatencyMin
type=9
unit=nanosecond
desc=Broker latency through this queue (Max)
name=messageLatencyMax
type=9
unit=nanosecond
desc=Broker latency through this queue (Average)
name=messageLatencyAverage
type=9
unit=nanosecond
argCount=0
desc=Discard all messages on queue
name=purge
	  *******    MENU   *************
#########################################################

1. Broker Query Request
2. Package Query Request
3. Class Query Request
4. Schema Query Request
5. Method Request
0. Exit

#########################################################
Please Enter your choice for REQUEST
0
Management Client is stopping....


------------------

END OF THE OUTPUT


Best Regards,
Rahul




On Jul 9 2008, Ted Ross wrote:

> mehtar@cs.man.ac.uk wrote:
> > On Jul 8 2008, Ted Ross wrote:
> >
> >> mehtar@cs.man.ac.uk wrote:
> >> > Hello Ted,
> >> >
> >> > encoder is an instance of AbstractEncoder class under > 
> >> org.apache.qpidity.transport.codec.Encoder. And thanks for pointing > 
> >> the duplication.
> >> >
> >> > Yes, you are correct i checked the spec. and it (bin128) is encoded 
> >> as > 16 octets. I added the following method for encoding the 128 bin 
> >> > schema hash with help of Rafael. so you mean this will not help to 
> >> > encode the schema... /* public void writeBin128(byte[] s) { if (s 
> >> == > null) { s = new byte[16]; } else if (s.length != 16) { throw new 
> >> > IllegalArgumentException("" + s); }
> >> >
> >> > put(s);
> >> > }
> >> > */
> >> >
> >> > could you please let me know which method can encode this schema or 
> >> is > there any method in AbstractEncoder which can do this OR How can 
> >> i > encode this.
> >> >
> >> > Thanks in advance.
> >> >
> >> > BR,
> >> > Rahul
> >> >
> >> Rahul,
> >>
> >> I think your writeBin128 should work correctly.  This encoding method 
> >> should be used to encode the schema hash in the schema request 
> >> message.  Let me know how it works.
> >>
> >> -Ted
> >>
> >>
> >
> > Thank you Ted for your reply. I will let you know but one more 
> > question before this.
> >
> > can we send multiple request (AM1B, AM1P, AM1Q, AM1S etc...) to broker 
> > to fetch the management information on the SAME SESSION ?
> Yes, you should be able to do everything on the same session.
> >
> > I am trying to request multiple request on the same session ang 
> > getting an exception "IllegalMonitorStateException" on 
> > session.endData(); statement in the following code snippet.
> >
> > When while loop goes first time then everything is okay. but for the 
> > second request when it reaches "session.endData();" then java throws 
> > this above mentioned exception.
> I think the problem is your sequence of calls.  The API expects the 
> following sequence per message:
> 
>     session.messageTransfer
>     session.data
>     session.endData
> 
> In your code, the messageTransfer call is outside and before the loop.  
> This means that the second time you try to transmit, you are calling 
> session.data without having called session.messageTransfer first.  The 
> session is in the incorrect state for a data call, thus the exception.
> >
> > Code Snippet
> > -----
> >
> > class ...{
> >
> > ...
> >
> > public void main(String a[])..... {
> > ....
> > ....
> >
> > Connection con = Client.createConnection();
> >         ByteBuffer message= ByteBuffer.allocate(500);
> >         ManagementEncoder encoder=new ManagementEncoder(message);
> >
> >         try
> >         {    // connect to local host on default port 5672
> >             con.connect("localhost", 5672, "test", "guest", "guest");
> >         }
> >         catch(Exception e)
> >         {
> >             System.out.print("Error connecting to broker");
> >             e.printStackTrace();
> >         }
> >
> >         // Create session
> >         Session session = con.createSession(0);
> >         .......
> >         ......
> >
> >         // transfer message to "qpid.management" exchange
> >                 session.messageTransfer("qpid.management", 
> > MessageAcceptMode.EXPLICIT,MessageAcquireMode.PRE_ACQUIRED);
> >         session.header(deliveryProps,messageProps);
> >         ......
> >         ......
> >       boolean flag=true;
> >        
> >         while(flag)
> >         {
> >
> >             BufferedReader br = new BufferedReader(new 
> > InputStreamReader(System.in));
> >             int choice=0;
> >
> >             choice = Integer.parseInt(br.readLine().trim());
> >            
> >             switch (choice)
> >             {
> >             // send broker request
> >             case 1:
> >                 p.opcode="AM1B";
> >                 message.clear();
> >                 try {
> >                     message.put(p.opcode.getBytes("UTF-8"));
> >                 } catch (UnsupportedEncodingException e1) {
> >                     e1.printStackTrace();
> >                 }
> >                 break;
> >
> >
> >             case 2:
> >
> >                          // send package request
> >                 p.opcode="AM1P";
> >                 message.clear();
> >                 try {
> >                     message.put(p.opcode.getBytes("UTF-8"));
> >                 } catch (UnsupportedEncodingException e1) {
> >                     e1.printStackTrace();
> >                 }
> >                 break;
> >
> >             case 3:   
> >                 // send class request
> >                              p.opcode="AM1Q";
> >                 p.sequenceNo=600;
> >                 p.packageName="qpid";
> >                 message.clear();
> >                 ...
> >                 ...
> >             break;
> >
> >             case 4:
> >             // send schema request
> >                       p.opcode="AM1S";
> >             .....
> >             .... .
> >             break;
> >            
> >             // switch closed
> >             }
> >
> >             message.flip();
> >             // send message
> >             session.data(message);
> >            
> > // *********GETTING EXCEPTION HERE IllegalMonitorStateException*********
> >             session.endData();
> >             // confirm completion
> >             session.sync();
> >            
> >         // while closed
> >             }
> >        
> >     session.sessionDetach(session.getName());
> >             try
> >             {    // close connection
> >                 con.close();
> >             }
> >             catch(Exception e)
> >             {
> >             System.out.print("Error closing broker connection");
> >                 e.printStackTrace();
> > // main close            }
> > }
> > // class closed
> > }
> > --------
> > End of the code snippet
> >
> > can i use the same session for sending the multiple request?
> >
> >
> > Thank you so much.
> > BR,
> > /rahul
> >
> 
> 

Re: Schema Request

Posted by me...@cs.man.ac.uk.
Thank you Ted and Rajith,

It works now.

BR,
Rahul

On Jul 9 2008, Rajith Attapattu wrote:

> >
> >   session.messageTransfer
> >   session.data
> >   session.endData
> >
> > In your code, the messageTransfer call is outside and before the loop.
> >  This means that the second time you try to transmit, you are calling
> > session.data without having called session.messageTransfer first.  The
> > session is in the incorrect state for a data call, thus the exception.
> 
> 
> It should be
> session.messageTransfer
> session.headers
> session.data
> session.endData
> 
> Regards,
> 
> Rajith
> 

Re: Schema Request

Posted by Rajith Attapattu <ra...@gmail.com>.
>
>   session.messageTransfer
>   session.data
>   session.endData
>
> In your code, the messageTransfer call is outside and before the loop.
>  This means that the second time you try to transmit, you are calling
> session.data without having called session.messageTransfer first.  The
> session is in the incorrect state for a data call, thus the exception.


It should be
session.messageTransfer
session.headers
session.data
session.endData

Regards,

Rajith

Re: Schema Request

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> On Jul 8 2008, Ted Ross wrote:
>
>> mehtar@cs.man.ac.uk wrote:
>> > Hello Ted,
>> >
>> > encoder is an instance of AbstractEncoder class under > 
>> org.apache.qpidity.transport.codec.Encoder. And thanks for pointing > 
>> the duplication.
>> >
>> > Yes, you are correct i checked the spec. and it (bin128) is encoded 
>> as > 16 octets. I added the following method for encoding the 128 bin 
>> > schema hash with help of Rafael. so you mean this will not help to 
>> > encode the schema... /* public void writeBin128(byte[] s) { if (s 
>> == > null) { s = new byte[16]; } else if (s.length != 16) { throw new 
>> > IllegalArgumentException("" + s); }
>> >
>> > put(s);
>> > }
>> > */
>> >
>> > could you please let me know which method can encode this schema or 
>> is > there any method in AbstractEncoder which can do this OR How can 
>> i > encode this.
>> >
>> > Thanks in advance.
>> >
>> > BR,
>> > Rahul
>> >
>> Rahul,
>>
>> I think your writeBin128 should work correctly.  This encoding method 
>> should be used to encode the schema hash in the schema request 
>> message.  Let me know how it works.
>>
>> -Ted
>>
>>
>
> Thank you Ted for your reply. I will let you know but one more 
> question before this.
>
> can we send multiple request (AM1B, AM1P, AM1Q, AM1S etc...) to broker 
> to fetch the management information on the SAME SESSION ?
Yes, you should be able to do everything on the same session.
>
> I am trying to request multiple request on the same session ang 
> getting an exception "IllegalMonitorStateException" on 
> session.endData(); statement in the following code snippet.
>
> When while loop goes first time then everything is okay. but for the 
> second request when it reaches "session.endData();" then java throws 
> this above mentioned exception.
I think the problem is your sequence of calls.  The API expects the 
following sequence per message:

    session.messageTransfer
    session.data
    session.endData

In your code, the messageTransfer call is outside and before the loop.  
This means that the second time you try to transmit, you are calling 
session.data without having called session.messageTransfer first.  The 
session is in the incorrect state for a data call, thus the exception.
>
> Code Snippet
> -----
>
> class ...{
>
> ...
>
> public void main(String a[])..... {
> ....
> ....
>
> Connection con = Client.createConnection();
>         ByteBuffer message= ByteBuffer.allocate(500);
>         ManagementEncoder encoder=new ManagementEncoder(message);
>
>         try
>         {    // connect to local host on default port 5672
>             con.connect("localhost", 5672, "test", "guest", "guest");
>         }
>         catch(Exception e)
>         {
>             System.out.print("Error connecting to broker");
>             e.printStackTrace();
>         }
>
>         // Create session
>         Session session = con.createSession(0);
>         .......
>         ......
>
>         // transfer message to "qpid.management" exchange
>                 session.messageTransfer("qpid.management", 
> MessageAcceptMode.EXPLICIT,MessageAcquireMode.PRE_ACQUIRED);
>         session.header(deliveryProps,messageProps);
>         ......
>         ......
>       boolean flag=true;
>        
>         while(flag)
>         {
>
>             BufferedReader br = new BufferedReader(new 
> InputStreamReader(System.in));
>             int choice=0;
>
>             choice = Integer.parseInt(br.readLine().trim());
>            
>             switch (choice)
>             {
>             // send broker request
>             case 1:
>                 p.opcode="AM1B";
>                 message.clear();
>                 try {
>                     message.put(p.opcode.getBytes("UTF-8"));
>                 } catch (UnsupportedEncodingException e1) {
>                     e1.printStackTrace();
>                 }
>                 break;
>
>
>             case 2:
>
>                          // send package request
>                 p.opcode="AM1P";
>                 message.clear();
>                 try {
>                     message.put(p.opcode.getBytes("UTF-8"));
>                 } catch (UnsupportedEncodingException e1) {
>                     e1.printStackTrace();
>                 }
>                 break;
>
>             case 3:   
>                 // send class request
>                              p.opcode="AM1Q";
>                 p.sequenceNo=600;
>                 p.packageName="qpid";
>                 message.clear();
>                 ...
>                 ...
>             break;
>
>             case 4:
>             // send schema request
>                       p.opcode="AM1S";
>             .....
>             .... .
>             break;
>            
>             // switch closed
>             }
>
>             message.flip();
>             // send message
>             session.data(message);
>            
> // *********GETTING EXCEPTION HERE IllegalMonitorStateException*********
>             session.endData();
>             // confirm completion
>             session.sync();
>            
>         // while closed
>             }
>        
>     session.sessionDetach(session.getName());
>             try
>             {    // close connection
>                 con.close();
>             }
>             catch(Exception e)
>             {
>             System.out.print("Error closing broker connection");
>                 e.printStackTrace();
> // main close            }
> }
> // class closed
> }
> --------
> End of the code snippet
>
> can i use the same session for sending the multiple request?
>
>
> Thank you so much.
> BR,
> /rahul
>


Re: Schema Request

Posted by me...@cs.man.ac.uk.
On Jul 8 2008, Ted Ross wrote:

> mehtar@cs.man.ac.uk wrote:
> > Hello Ted,
> >
> > encoder is an instance of AbstractEncoder class under 
> > org.apache.qpidity.transport.codec.Encoder. And thanks for pointing 
> > the duplication.
> >
> > Yes, you are correct i checked the spec. and it (bin128) is encoded as 
> > 16 octets. I added the following method for encoding the 128 bin 
> > schema hash with help of Rafael. so you mean this will not help to 
> > encode the schema... /* public void writeBin128(byte[] s) { if (s == 
> > null) { s = new byte[16]; } else if (s.length != 16) { throw new 
> > IllegalArgumentException("" + s); }
> >
> > put(s);
> > }
> > */
> >
> > could you please let me know which method can encode this schema or is 
> > there any method in AbstractEncoder which can do this OR How can i 
> > encode this.
> >
> > Thanks in advance.
> >
> > BR,
> > Rahul
> >
> Rahul,
> 
> I think your writeBin128 should work correctly.  This encoding method 
> should be used to encode the schema hash in the schema request message.  
> Let me know how it works.
> 
> -Ted
> 
> 

Thank you Ted for your reply. I will let you know but one more question 
before this.

can we send multiple request (AM1B, AM1P, AM1Q, AM1S etc...) to broker to 
fetch the management information on the SAME SESSION ?

I am trying to request multiple request on the same session ang getting an 
exception "IllegalMonitorStateException" on session.endData(); statement in 
the following code snippet.

When while loop goes first time then everything is okay. but for the second 
request when it reaches "session.endData();" then java throws this above 
mentioned exception.

Code Snippet
-----

class ...{

...

public void main(String a[])..... { 

....
....

Connection con = Client.createConnection();
		ByteBuffer message= ByteBuffer.allocate(500);
		ManagementEncoder encoder=new ManagementEncoder(message);

		try
		{	// connect to local host on default port 5672
			con.connect("localhost", 5672, "test", "guest", "guest");
		}
		catch(Exception e)
		{
			System.out.print("Error connecting to broker");
			e.printStackTrace();
		}

		// Create session
		Session session = con.createSession(0);
		.......
		......

		// transfer message to "qpid.management" exchange
                 session.messageTransfer("qpid.management", 
MessageAcceptMode.EXPLICIT,MessageAcquireMode.PRE_ACQUIRED);
		session.header(deliveryProps,messageProps);
		......
		......
       boolean flag=true;
		
		while(flag)
		{

			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int choice=0;

			choice = Integer.parseInt(br.readLine().trim());
			
			switch (choice)
			{
			// send broker request
			case 1:
				p.opcode="AM1B";
				message.clear();
				try {
					message.put(p.opcode.getBytes("UTF-8"));
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
				break;


			case 2:

                          // send package request
				p.opcode="AM1P";
				message.clear();
				try {
					message.put(p.opcode.getBytes("UTF-8"));
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
				break;

			case 3:	
				// send class request
                              p.opcode="AM1Q";
				p.sequenceNo=600;
				p.packageName="qpid";
				message.clear();
				...
				...
			break;

			case 4:
			// send schema request
                       p.opcode="AM1S";
			.....
			.... .
			break;
			
			// switch closed
			}

			message.flip();
			// send message
			session.data(message);
			
// *********GETTING EXCEPTION HERE IllegalMonitorStateException*********
			session.endData();
			// confirm completion
			session.sync();
			
		// while closed
			}
		
	session.sessionDetach(session.getName());
			try
			{	// close connection
				con.close();
			}
			catch(Exception e)
			{
			System.out.print("Error closing broker connection");
				e.printStackTrace();
// main close			}
}
// class closed
}
--------
End of the code snippet

can i use the same session for sending the multiple request?


Thank you so much.
BR,
/rahul


Re: Schema Request

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> Hello Ted,
>
> encoder is an instance of AbstractEncoder class under 
> org.apache.qpidity.transport.codec.Encoder. And thanks for pointing 
> the duplication.
>
> Yes, you are correct i checked the spec. and it (bin128) is encoded as 
> 16 octets. I added the following method for encoding the 128 bin 
> schema hash with help of Rafael. so you mean this will not help to 
> encode the schema... /* public void writeBin128(byte[] s) { if (s == 
> null) { s = new byte[16]; } else if (s.length != 16) { throw new 
> IllegalArgumentException("" + s); }
>
> put(s);
> }
> */
>
> could you please let me know which method can encode this schema or is 
> there any method in AbstractEncoder which can do this OR How can i 
> encode this.
>
> Thanks in advance.
>
> BR,
> Rahul
>
Rahul,

I think your writeBin128 should work correctly.  This encoding method 
should be used to encode the schema hash in the schema request message.  
Let me know how it works.

-Ted


Re: Schema Request

Posted by me...@cs.man.ac.uk.
On Jul 7 2008, Ted Ross wrote:

> mehtar@cs.man.ac.uk wrote:
> > Hello Ted/Anybody,
> >
> > Could you please correct me about the schema request (AM1S) which I am 
> > sending to broker to get the schema response for particular class?
> >
> > Could you please let me know what is wrong here. I think schema 
> > request is not healthy. Please guide me here. I am not receiving the 
> > schema response with this schema request
> >
> > Here is the code snippet of Schema request and Schema response.
> > // Code snippet for Schema Request (AM1S)
> > ....
> >
> > p.opcode="AM1S";
> > p.sequenceNo=500;
> > p.packageName="qpid";
> > p.classname="vhost";
> >
> > message.clear();
> > try {
> > // encode the opcode
> > message.put(p.opcode.getBytes("UTF-8"));
> > message.putInt( p.sequenceNo);
> > // encode the package name
> > encoder.writeStr8(p.packageName);
> > message.putShort((byte) p.packageName.length());
> > message.put(p.packageName.getBytes("UTF-8"));
> > // encode the class name
> > encoder.writeStr8(p.classname);
> > message.putShort((byte) p.classname.length());
> > message.put(p.classname.getBytes("UTF-8"));
> > // encode the schema hash
> > // *** schema has contents which it got from // byte[] 
> > schemaHash=decoder.readBin128(); something like [B@2bb514  ***
> >
> > encoder.writeBin128(schemaHash);
> > message.put((byte) schemaHash.length);
> > message.put(schemaHash);
> > } catch (UnsupportedEncodingException e) {
> > e.printStackTrace();
> > }
> > ........
> > ........
> >
> > ------
> >
> > //Start Code snippet Schema Response (AM1s)
> >
> > String packname = decoder.readStr8();
> > System.out.println("Package Name: " + packname);
> > String clasnam = decoder.readStr8();
> > System.out.println("Class Name: " + clasnam);
> >                
> > // get the decoded schema hash
> > decoder.readBin128();
> > // get the decoded properties contents
> > int propCnt = decoder.readUint16();
> > System.out.println("Property content:   " + propCnt);
> > long statCnt = decoder.readUint16();
> > System.out.println("Statistic content:   " + statCnt);
> > int methodCnt = decoder.readUint16();
> > System.out.println("Method content:   " + methodCnt);
> > int eventCnt = decoder.readUint16();
> > System.out.println("Event content:   " + eventCnt);
> >     
> > for( int i = 0; i < propCnt; i++ )
> > {    // decode the MAP
> > Map<String,Object> map = decoder.readMap();
> > }
> >                
> > for( int i = 0; i < statCnt; i++ )
> > {
> > // decode the MAP
> > Map<String,Object> map = decoder.readMap();
> > }
> >                
> > for( int i = 0; i < methodCnt; i++ )
> > {    // decode the MAP
> > Map<String,Object> map = decoder.readMap();
> > }
> >                
> > for( int i = 0; i < eventCnt; i++ )
> > {    // decode the MAP
> > Map<String,Object> map = decoder.readMap();
> > }
> >                     ---------
> > End of the Code
> >
> > Thank you.
> >
> > Best Regards,
> > Rahul
> >
> Rahul,
> 
> There's a problem with the encoding of the bin128 for the hash value.  
> If you look at the AMQP 0-10 specification for the proper encoding for a 
> bin128 value, you will see that it is encoded as 16 octets (no length 
> field).  Your code prepends a one-byte length which causes the value to 
> be incorrect/unmatched from the viewpoint of the management broker.
> 
> In looking at your code fragment, I am unclear as to what "encoder" is 
> and why you use it.  In the following section, you invoke "writeStr8" on 
> "encoder" but then you manually encode the string into "message".
> 
>     // encode the package name
>     encoder.writeStr8(p.packageName);
>     message.putShort((byte) p.packageName.length());
>     message.put(p.packageName.getBytes("UTF-8"));
> 
> Regards,
> 
> -Ted
> 
> 


Hello Ted,

encoder is an instance of AbstractEncoder class under 
org.apache.qpidity.transport.codec.Encoder. And thanks for pointing the 
duplication.

Yes, you are correct i checked the spec. and it (bin128) is encoded as 16 
octets. I added the following method for encoding the 128 bin schema hash 
with help of Rafael. so you mean this will not help to encode the schema... 
/* public void writeBin128(byte[] s) { if (s == null) { s = new byte[16]; } 
else if (s.length != 16) { throw new IllegalArgumentException("" + s); }

put(s);
}
*/

could you please let me know which method can encode this schema or is 
there any method in AbstractEncoder which can do this OR How can i encode 
this.

Thanks in advance.

BR,
Rahul


Re: Schema Request

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> Hello Ted/Anybody,
>
> Could you please correct me about the schema request (AM1S) which I am 
> sending to broker to get the schema response for particular class?
>
> Could you please let me know what is wrong here. I think schema 
> request is not healthy. Please guide me here. I am not receiving the 
> schema response with this schema request
>
> Here is the code snippet of Schema request and Schema response.
> // Code snippet for Schema Request (AM1S)
> ....
>
> p.opcode="AM1S";
> p.sequenceNo=500;
> p.packageName="qpid";
> p.classname="vhost";
>
> message.clear();
> try {
> // encode the opcode
> message.put(p.opcode.getBytes("UTF-8"));
> message.putInt( p.sequenceNo);
> // encode the package name
> encoder.writeStr8(p.packageName);
> message.putShort((byte) p.packageName.length());
> message.put(p.packageName.getBytes("UTF-8"));
> // encode the class name
> encoder.writeStr8(p.classname);
> message.putShort((byte) p.classname.length());
> message.put(p.classname.getBytes("UTF-8"));
> // encode the schema hash
> // *** schema has contents which it got from // byte[] 
> schemaHash=decoder.readBin128(); something like [B@2bb514  ***
>
> encoder.writeBin128(schemaHash);
> message.put((byte) schemaHash.length);
> message.put(schemaHash);
> } catch (UnsupportedEncodingException e) {
> e.printStackTrace();
> }
> ........
> ........
>
> ------
>
> //Start Code snippet Schema Response (AM1s)
>
> String packname = decoder.readStr8();
> System.out.println("Package Name: " + packname);
> String clasnam = decoder.readStr8();
> System.out.println("Class Name: " + clasnam);
>                
> // get the decoded schema hash
> decoder.readBin128();
> // get the decoded properties contents
> int propCnt = decoder.readUint16();
> System.out.println("Property content:   " + propCnt);
> long statCnt = decoder.readUint16();
> System.out.println("Statistic content:   " + statCnt);
> int methodCnt = decoder.readUint16();
> System.out.println("Method content:   " + methodCnt);
> int eventCnt = decoder.readUint16();
> System.out.println("Event content:   " + eventCnt);
>     
> for( int i = 0; i < propCnt; i++ )
> {    // decode the MAP
> Map<String,Object> map = decoder.readMap();
> }
>                
> for( int i = 0; i < statCnt; i++ )
> {
> // decode the MAP
> Map<String,Object> map = decoder.readMap();
> }
>                
> for( int i = 0; i < methodCnt; i++ )
> {    // decode the MAP
> Map<String,Object> map = decoder.readMap();
> }
>                
> for( int i = 0; i < eventCnt; i++ )
> {    // decode the MAP
> Map<String,Object> map = decoder.readMap();
> }
>                     ---------
> End of the Code
>
> Thank you.
>
> Best Regards,
> Rahul
>
Rahul,

There's a problem with the encoding of the bin128 for the hash value.  
If you look at the AMQP 0-10 specification for the proper encoding for a 
bin128 value, you will see that it is encoded as 16 octets (no length 
field).  Your code prepends a one-byte length which causes the value to 
be incorrect/unmatched from the viewpoint of the management broker.

In looking at your code fragment, I am unclear as to what "encoder" is 
and why you use it.  In the following section, you invoke "writeStr8" on 
"encoder" but then you manually encode the string into "message".

    // encode the package name
    encoder.writeStr8(p.packageName);
    message.putShort((byte) p.packageName.length());
    message.put(p.packageName.getBytes("UTF-8"));

Regards,

-Ted