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;
022
023 import java.nio.*;
024 import java.util.*;
025
026 import org.apache.qpid.transport.*;
027 import org.apache.qpid.transport.network.mina.MinaHandler;
028
029
030 /**
031 * ToyClient
032 *
033 * @author Rafael H. Schloming
034 */
035
036 class ToyClient implements SessionListener
037 {
038 public void opened(Session ssn) {}
039
040 public void exception(Session ssn, SessionException exc)
041 {
042 exc.printStackTrace();
043 }
044
045 public void message(Session ssn, MessageTransfer xfr)
046 {
047 System.out.println("msg: " + xfr);
048 }
049
050 public void closed(Session ssn) {}
051
052 public static final void main(String[] args)
053 {
054 Connection conn = new Connection();
055 conn.connect("0.0.0.0", 5672, null, "guest", "guest", false);
056 Session ssn = conn.createSession();
057 ssn.setSessionListener(new ToyClient());
058
059 ssn.queueDeclare("asdf", null, null);
060 ssn.sync();
061
062 Map<String,Object> nested = new LinkedHashMap<String,Object>();
063 nested.put("list", Arrays.asList("one", "two", "three"));
064 Map<String,Object> map = new LinkedHashMap<String,Object>();
065
066 map.put("str", "this is a string");
067
068 map.put("+int", 3);
069 map.put("-int", -3);
070 map.put("maxint", Integer.MAX_VALUE);
071 map.put("minint", Integer.MIN_VALUE);
072
073 map.put("+short", (short) 1);
074 map.put("-short", (short) -1);
075 map.put("maxshort", (short) Short.MAX_VALUE);
076 map.put("minshort", (short) Short.MIN_VALUE);
077
078 map.put("float", (float) 3.3);
079 map.put("double", 4.9);
080 map.put("char", 'c');
081
082 map.put("table", nested);
083 map.put("list", Arrays.asList(1, 2, 3));
084 map.put("binary", new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
085
086 ssn.messageTransfer("asdf", MessageAcceptMode.EXPLICIT,
087 MessageAcquireMode.PRE_ACQUIRED,
088 new Header(new DeliveryProperties(),
089 new MessageProperties()
090 .setApplicationHeaders(map)),
091 "this is the data");
092
093 ssn.messageTransfer("fdsa", MessageAcceptMode.EXPLICIT,
094 MessageAcquireMode.PRE_ACQUIRED,
095 null,
096 "this should be rejected");
097 ssn.sync();
098
099 Future<QueueQueryResult> future = ssn.queueQuery("asdf");
100 System.out.println(future.get().getQueue());
101 ssn.sync();
102 ssn.close();
103 conn.close();
104 }
105
106 }
|