You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jr...@apache.org on 2018/03/20 18:33:38 UTC
[3/9] qpid-proton git commit: PROTON-1799: Remove deprecated bindings
and APIs
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/php/get_include_dir.php
----------------------------------------------------------------------
diff --git a/proton-c/bindings/php/get_include_dir.php b/proton-c/bindings/php/get_include_dir.php
deleted file mode 100644
index 6103e41..0000000
--- a/proton-c/bindings/php/get_include_dir.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/*
- *
- * 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.
- *
-*/
-
-
-$prefix = $argv[1];
-$include_path = ini_get("include_path");
-
-$php_dir = null;
-$pear_dir = null;
-$abs_dir = null;
-
-foreach (explode(PATH_SEPARATOR, $include_path) as $include_dir) {
- if (strpos($include_dir, ".") === false &&
- strpos($include_dir, $prefix) === 0) {
- $abs_dir = $include_dir;
- $suffix = substr($abs_dir, strlen($prefix));
- if (strpos($suffix, "php") !== false) {
- $php_dir = $abs_dir;
- }
- if (strpos($suffix, "pear") !== false) {
- $pear_dir = $abs_dir;
- }
- }
-}
-
-if ($php_dir) {
- print $php_dir;
-} else if ($pear_dir) {
- print $pear_dir;
-} else if ($abs_dir) {
- print $abs_dir;
-}
-
-print "\n";
-
-?>
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/php/php.i
----------------------------------------------------------------------
diff --git a/proton-c/bindings/php/php.i b/proton-c/bindings/php/php.i
deleted file mode 100644
index 6e927f7..0000000
--- a/proton-c/bindings/php/php.i
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * 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.
- */
-
-%module cproton
-
-// provided by SWIG development libraries
-%include php.swg
-
-#if SWIG_VERSION < 0x020000
-%include compat.swg
-#endif
-
-%header %{
-/* Include the headers needed by the code in this wrapper file */
-#include <proton/types.h>
-#include <proton/connection.h>
-#include <proton/condition.h>
-#include <proton/delivery.h>
-#include <proton/event.h>
-#include <proton/message.h>
-#include <proton/messenger.h>
-#include <proton/session.h>
-#include <proton/url.h>
-#include <proton/reactor.h>
-#include <proton/handlers.h>
-#include <proton/sasl.h>
-
-#define zend_error_noreturn zend_error
-%}
-
-%apply (char *STRING, int LENGTH) { (char *STRING, size_t LENGTH) };
-
-// ssize_t return value
-//
-%typemap(out) ssize_t {
- ZVAL_LONG($result, (long)$1);
-}
-
-// (char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN)
-//
-// typemap for binary buffer output arguments. Given an uninitialized pointer for a
-// buffer (OUTPUT_BUFFER) and a pointer to an un-initialized size/error (OUTPUT_LEN), a buffer
-// will be allocated and filled with binary data. *OUTPUT_BUFFER will be set to the address
-// of the allocated buffer. *OUTPUT_LEN will be set to the size of the data. The maximum
-// length of the buffer must be provided by a separate argument.
-//
-// The return value is an array, with [0] set to the length of the output buffer OR an
-// error code and [1] set to the returned string object. This value is appended to the
-// function's return value (also an array).
-//
-%typemap(in,numinputs=0) (char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN) (char *Buff = 0, ssize_t outLen = 0) {
- // setup locals for output.
- $1 = &Buff;
- $2 = &outLen;
-}
-%typemap(argout,fragment="t_output_helper") (char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN) {
- // convert to array: [0]=len||error, [1]=binary string
- zval *tmp;
- ALLOC_INIT_ZVAL(tmp);
- array_init(tmp);
- ssize_t len = *($2);
- add_next_index_long(tmp, len); // write the len|error code
- if (len >= 0) {
- add_next_index_stringl(tmp, *($1), len, 0); // 0 == take ownership of $1 memory
- } else {
- add_next_index_string(tmp, "", 1); // 1 = strdup the ""
- }
- t_output_helper(&$result, tmp); // append it to output array
-}
-
-%typemap(in) pn_bytes_t {
- if (ZVAL_IS_NULL(*$input)) {
- $1.start = NULL;
- $1.size = 0;
- } else {
- $1.start = Z_STRVAL_PP($input);
- $1.size = Z_STRLEN_PP($input);
- }
-}
-
-%typemap(out) pn_bytes_t {
- ZVAL_STRINGL($result, $1.start, $1.size, 1);
-}
-
-%typemap(in) pn_uuid_t {
- memmove($1.bytes, Z_STRVAL_PP($input), 16);
-}
-
-%typemap(out) pn_uuid_t {
- ZVAL_STRINGL($result, $1.bytes, 16, 1);
-}
-
-%typemap(in) pn_decimal128_t {
- memmove($1.bytes, Z_STRVAL_PP($input), 16);
-}
-
-%typemap(out) pn_decimal128_t {
- ZVAL_STRINGL($result, $1.bytes, 16, 1);
-}
-
-// The PHP SWIG typedefs define the typemap STRING, LENGTH to be binary safe (allow
-// embedded \0's).
-//
-
-// allow pn_link_send/pn_input's input buffer to be binary safe
-ssize_t pn_link_send(pn_link_t *transport, char *STRING, size_t LENGTH);
-%ignore pn_link_send;
-ssize_t pn_transport_input(pn_transport_t *transport, char *STRING, size_t LENGTH);
-%ignore pn_transport_input;
-
-
-// Use the OUTPUT_BUFFER,OUTPUT_LEN typemap to allow these functions to return
-// variable length binary data.
-
-%rename(pn_link_recv) wrap_pn_link_recv;
-// in PHP: array = pn_link_recv(link, MAXLEN);
-// array[0] = size || error code
-// array[1] = native string containing binary data
-%inline %{
- void wrap_pn_link_recv(pn_link_t *link, size_t maxCount, char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN) {
- *OUTPUT_BUFFER = emalloc(sizeof(char) * maxCount);
- *OUTPUT_LEN = pn_link_recv(link, *OUTPUT_BUFFER, maxCount );
- }
-%}
-%ignore pn_link_recv;
-
-%rename(pn_transport_output) wrap_pn_transport_output;
-// in PHP: array = pn_transport_output(transport, MAXLEN);
-// array[0] = size || error code
-// array[1] = native string containing binary data
-%inline %{
- void wrap_pn_transport_output(pn_transport_t *transport, size_t maxCount, char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN) {
- *OUTPUT_BUFFER = emalloc(sizeof(char) * maxCount);
- *OUTPUT_LEN = pn_transport_output(transport, *OUTPUT_BUFFER, maxCount);
- }
-%}
-%ignore pn_transport_output;
-
-%rename(pn_message_encode) wrap_pn_message_encode;
-%inline %{
- void wrap_pn_message_encode(pn_message_t *message, size_t maxCount, char **OUTPUT_BUFFER, ssize_t *OUTPUT_LEN) {
- *OUTPUT_BUFFER = emalloc(sizeof(char) * maxCount);
- *OUTPUT_LEN = maxCount;
- int err = pn_message_encode(message, *OUTPUT_BUFFER, OUTPUT_LEN);
- if (err) {
- *OUTPUT_LEN = err;
- efree(*OUTPUT_BUFFER);
- }
- }
-%}
-%ignore pn_message_encode;
-
-
-
-//
-// allow pn_delivery/pn_delivery_tag to accept a binary safe string:
-//
-
-%rename(pn_delivery) wrap_pn_delivery;
-// in PHP: delivery = pn_delivery(link, "binary safe string");
-//
-%inline %{
- pn_delivery_t *wrap_pn_delivery(pn_link_t *link, char *STRING, size_t LENGTH) {
- return pn_delivery(link, pn_dtag(STRING, LENGTH));
- }
-%}
-%ignore pn_delivery;
-
-// pn_delivery_tag: output a copy of the pn_delivery_tag buffer
-//
-%typemap(in,numinputs=0) (const char **RETURN_STRING, size_t *RETURN_LEN) (char *Buff = 0, size_t outLen = 0) {
- $1 = &Buff; // setup locals for holding output values.
- $2 = &outLen;
-}
-%typemap(argout) (const char **RETURN_STRING, size_t *RETURN_LEN) {
- // This allocates a copy of the binary buffer for return to the caller
- ZVAL_STRINGL($result, *($1), *($2), 1); // 1 = duplicate the input buffer
-}
-
-// Suppress "Warning(451): Setting a const char * variable may leak memory." on pn_delivery_tag_t
-%warnfilter(451) pn_delivery_tag_t;
-%rename(pn_delivery_tag) wrap_pn_delivery_tag;
-// in PHP: str = pn_delivery_tag(delivery);
-//
-%inline %{
- void wrap_pn_delivery_tag(pn_delivery_t *d, const char **RETURN_STRING, size_t *RETURN_LEN) {
- pn_delivery_tag_t tag = pn_delivery_tag(d);
- *RETURN_STRING = tag.start;
- *RETURN_LEN = tag.size;
- }
-%}
-%ignore pn_delivery_tag;
-
-
-
-//
-// reference counter management for passing a context to/from the listener/connector
-//
-
-%typemap(in) void *PHP_CONTEXT {
- // since we hold a pointer to the context we must increment the reference count
- Z_ADDREF_PP($input);
- $1 = *$input;
-}
-
-// return the context. Apparently, PHP won't let us return a pointer to a reference
-// counted zval, so we must return a copy of the data
-%typemap(out) void * {
- *$result = *(zval *)($1);
- zval_copy_ctor($result);
-}
-
-%include "proton/cproton.i"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/php/proton.ini.in
----------------------------------------------------------------------
diff --git a/proton-c/bindings/php/proton.ini.in b/proton-c/bindings/php/proton.ini.in
deleted file mode 100644
index 51a774e..0000000
--- a/proton-c/bindings/php/proton.ini.in
+++ /dev/null
@@ -1,21 +0,0 @@
-;;
-; 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.
-;;
-
-; Enable cproton extension module
-@PROTON_INI@
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/php/proton.php
----------------------------------------------------------------------
diff --git a/proton-c/bindings/php/proton.php b/proton-c/bindings/php/proton.php
deleted file mode 100644
index 8cad1b2..0000000
--- a/proton-c/bindings/php/proton.php
+++ /dev/null
@@ -1,1119 +0,0 @@
-<?php
-
-/**
- * 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.
- **/
-
-include("cproton.php");
-
-class ProtonException extends Exception {}
-
-class Timeout extends ProtonException {}
-
-class MessengerException extends ProtonException {}
-
-class MessageException extends ProtonException {}
-
-function code2exc($err) {
- switch ($err) {
- case PN_TIMEOUT:
- return "Timeout";
- default:
- return null;
- }
-}
-
-class Messenger
-{
- private $impl;
-
- public function __construct($name=null) {
- $this->impl = pn_messenger($name);
- }
-
- public function __destruct() {
- pn_messenger_free($this->impl);
- }
-
- public function __toString() {
- return 'Messenger("' . pn_messenger_name($this->impl) . '")';
- }
-
- private function _check($value) {
- if ($value < 0) {
- $exc = code2exc($value);
- if ($exc == null) $exc = "MessengerException";
- throw new $exc("[$value]: " . pn_error_text(pn_messenger_error($this->impl)));
- } else {
- return $value;
- }
- }
-
- public function __get($name) {
- switch ($name) {
- case "name":
- return pn_messenger_name($this->impl);
- case "certificate":
- return pn_messenger_get_certificate($this->impl);
- case "private_key":
- return pn_messenger_get_private_key($this->impl);
- case "password":
- return pn_messenger_get_password($this->impl);
- case "trusted_certificates":
- return pn_messenger_get_trusted_certificates($this->impl);
- case "incoming":
- return $this->incoming();
- case "outgoing":
- return $this->outgoing();
- default:
- throw new Exception("unknown property: " . $name);
- }
- }
-
- public function __set($name, $value) {
- switch ($name) {
- case "certificate":
- $this->_check(pn_messenger_set_certificate($this->impl, $value));
- break;
- case "private_key":
- $this->_check(pn_messenger_set_private_key($this->impl, $value));
- break;
- case "password":
- $this->_check(pn_messenger_set_password($this->impl, $value));
- break;
- case "trusted_certificates":
- $this->_check(pn_messenger_set_trusted_certificates($this->impl, $value));
- break;
- case "timeout":
- $this->_check(pn_messenger_set_timeout($this->impl, $value));
- break;
- case "outgoing_window":
- $this->_check(pn_messenger_set_outgoing_window($this->impl, $value));
- break;
- case "incoming_window":
- $this->_check(pn_messenger_set_incoming_window($this->impl, $value));
- break;
- default:
- throw new Exception("unknown property: " . $name);
- }
- }
-
- public function start() {
- $this->_check(pn_messenger_start($this->impl));
- }
-
- public function stop() {
- $this->_check(pn_messenger_stop($this->impl));
- }
-
- public function subscribe($source) {
- if ($source == null) {
- throw new MessengerException("null source passed to subscribe");
- }
- $this->_check(pn_messenger_subscribe($this->impl, $source));
- }
-
- public function outgoing_tracker() {
- return pn_messenger_outgoing_tracker($this->impl);
- }
-
- public function put($message) {
- $message->_pre_encode();
- $this->_check(pn_messenger_put($this->impl, $message->impl));
- return $this->outgoing_tracker();
- }
-
- public function send($n = -1) {
- $this->_check(pn_messenger_send($this->impl, $n));
- }
-
- public function recv($n = -1) {
- $this->_check(pn_messenger_recv($this->impl, $n));
- }
-
- public function incoming_tracker() {
- return pn_messenger_incoming_tracker($this->impl);
- }
-
- public function get($message) {
- $this->_check(pn_messenger_get($this->impl, $message->impl));
- $message->_post_decode();
- return $this->incoming_tracker();
- }
-
- public function accept($tracker = null) {
- if ($tracker == null) {
- $tracker = $this->incoming_tracker();
- $flag = PN_CUMULATIVE;
- } else {
- $flag = 0;
- }
- $this->_check(pn_messenger_accept($this->impl, $tracker, $flag));
- }
-
- public function reject($tracker = null) {
- if ($tracker == null) {
- $tracker = $this->incoming_tracker();
- $flag = PN_CUMULATIVE;
- } else {
- $flag = 0;
- }
- $this->_check(pn_messenger_reject($this->impl, $tracker, $flag));
- }
-
- public function route($pattern, $address) {
- $this->_check(pn_messenger_route($this->impl, $pattern, $address));
- }
-
- public function outgoing() {
- return pn_messenger_outgoing($this->impl);
- }
-
- public function incoming() {
- return pn_messenger_incoming($this->impl);
- }
-
- public function status($tracker) {
- return pn_messenger_status($this->impl, $tracker);
- }
-
-}
-
-class Message {
-
- const DEFAULT_PRIORITY = PN_DEFAULT_PRIORITY;
-
- var $impl;
- var $_id;
- var $_correlation_id;
- public $instructions = null;
- public $annotations = null;
- public $properties = null;
- public $body = null;
-
- public function __construct() {
- $this->impl = pn_message();
- $this->_id = new Data(pn_message_id($this->impl));
- $this->_correlation_id = new Data(pn_message_correlation_id($this->impl));
- }
-
- public function __destruct() {
- pn_message_free($this->impl);
- }
-
- public function __tostring() {
- $tmp = pn_string("");
- pn_inspect($this->impl, $tmp);
- $result = pn_string_get($tmp);
- pn_free($tmp);
- return $result;
- }
-
- private function _check($value) {
- if ($value < 0) {
- $exc = code2exc($value);
- if ($exc == null) $exc = "MessageException";
- throw new $exc("[$value]: " . pn_message_error($this->impl));
- } else {
- return $value;
- }
- }
-
- public function __get($name) {
- if ($name == "impl")
- throw new Exception();
- $getter = "_get_$name";
- return $this->$getter();
- }
-
- public function __set($name, $value) {
- $setter = "_set_$name";
- $this->$setter($value);
- }
-
- function _pre_encode() {
- $inst = new Data(pn_message_instructions($this->impl));
- $ann = new Data(pn_message_annotations($this->impl));
- $props = new Data(pn_message_properties($this->impl));
- $body = new Data(pn_message_body($this->impl));
-
- $inst->clear();
- if ($this->instructions != null)
- $inst->put_object($this->instructions);
- $ann->clear();
- if ($this->annotations != null)
- $ann->put_object($this->annotations);
- $props->clear();
- if ($this->properties != null)
- $props->put_object($this->properties);
-
- $body->clear();
- if ($this->body != null) {
- $body->put_object($this->body);
- }
- }
-
- function _post_decode() {
- $inst = new Data(pn_message_instructions($this->impl));
- $ann = new Data(pn_message_annotations($this->impl));
- $props = new Data(pn_message_properties($this->impl));
- $body = new Data(pn_message_body($this->impl));
-
- if ($inst->next())
- $this->instructions = $inst->get_object();
- else
- $this->instructions = null;
- if ($ann->next())
- $this->annotations = $ann->get_object();
- else
- $this->annotations = null;
- if ($props->next())
- $this->properties = $props->get_object();
- else
- $this->properties = null;
- if ($body->next())
- $this->body = $body->get_object();
- else
- $this->body = null;
- }
-
- public function clear() {
- pn_message_clear($this->impl);
- $this->instructions = null;
- $this->annotations = null;
- $this->properties = null;
- $this->body = null;
- }
-
- private function _get_inferred() {
- return pn_message_is_inferred($this->impl);
- }
-
- private function _set_inferred($value) {
- $this->_check(pn_message_set_inferred($this->impl, $value));
- }
-
- private function _get_durable() {
- return pn_message_is_durable($this->impl);
- }
-
- private function _set_durable($value) {
- $this->_check(pn_message_set_durable($this->impl, $value));
- }
-
- private function _get_priority() {
- return pn_message_get_priority($this->impl);
- }
-
- private function _set_priority($value) {
- $this->_check(pn_message_set_priority($this->impl, $value));
- }
-
- private function _get_ttl() {
- return pn_message_get_ttl($this->impl);
- }
-
- private function _set_ttl($value) {
- $this->_check(pn_message_set_ttl($this->impl, $value));
- }
-
- private function _get_first_acquirer() {
- return pn_message_is_first_acquirer($this->impl);
- }
-
- private function _set_first_acquirer($value) {
- $this->_check(pn_message_set_first_acquirer($this->impl, $value));
- }
-
- private function _get_delivery_count() {
- return pn_message_get_delivery_count($this->impl);
- }
-
- private function _set_delivery_count($value) {
- $this->_check(pn_message_set_delivery_count($this->impl, $value));
- }
-
- private function _get_id() {
- return $this->_id->get_object();
- }
-
- private function _set_id($value) {
- $this->_id->rewind();
- $this->_id->put_object($value);
- }
-
- private function _get_user_id() {
- return pn_message_get_user_id($this->impl);
- }
-
- private function _set_user_id($value) {
- $this->_check(pn_message_set_user_id($this->impl, $value));
- }
-
- private function _get_address() {
- return pn_message_get_address($this->impl);
- }
-
- private function _set_address($value) {
- $this->_check(pn_message_set_address($this->impl, $value));
- }
-
- private function _get_subject() {
- return pn_message_get_subject($this->impl);
- }
-
- private function _set_subject($value) {
- $this->_check(pn_message_set_subject($this->impl, $value));
- }
-
- private function _get_reply_to() {
- return pn_message_get_reply_to($this->impl);
- }
-
- private function _set_reply_to($value) {
- $this->_check(pn_message_set_reply_to($this->impl, $value));
- }
-
- private function _get_correlation_id() {
- return $this->_correlation_id->get_object();
- }
-
- private function _set_correlation_id($value) {
- $this->_correlation_id->rewind();
- $this->_correlation_id->put_object($value);
- }
-
- private function _get_content_type() {
- return pn_message_get_content_type($this->impl);
- }
-
- private function _set_content_type($value) {
- $this->_check(pn_message_set_content_type($this->impl, $value));
- }
-
- private function _get_content_encoding() {
- return pn_message_get_content_encoding($this->impl);
- }
-
- private function _set_content_encoding($value) {
- $this->_check(pn_message_set_content_encoding($this->impl, $value));
- }
-
- private function _get_expiry_time() {
- return pn_message_get_expiry_time($this->impl);
- }
-
- private function _set_expiry_time($value) {
- $this->_check(pn_message_set_expiry_time($this->impl, $value));
- }
-
- private function _get_creation_time() {
- return pn_message_get_creation_time($this->impl);
- }
-
- private function _set_creation_time($value) {
- $this->_check(pn_message_set_creation_time($this->impl, $value));
- }
-
- private function _get_group_id() {
- return pn_message_get_group_id($this->impl);
- }
-
- private function _set_group_id($value) {
- $this->_check(pn_message_set_group_id($this->impl, $value));
- }
-
- private function _get_group_sequence() {
- return pn_message_get_group_sequence($this->impl);
- }
-
- private function _set_group_sequence($value) {
- $this->_check(pn_message_set_group_sequence($this->impl, $value));
- }
-
- private function _get_reply_to_group_id() {
- return pn_message_get_reply_to_group_id($this->impl);
- }
-
- private function _set_reply_to_group_id($value) {
- $this->_check(pn_message_set_reply_to_group_id($this->impl, $value));
- }
-
- public function encode() {
- $this->_pre_encode();
- $sz = 16;
- while (true) {
- list($err, $data) = pn_message_encode($this->impl, $sz);
- if ($err == PN_OVERFLOW) {
- $sz *= 2;
- continue;
- } else {
- $this->_check($err);
- return $data;
- }
- }
- }
-
- public function decode($data) {
- $this->_check(pn_message_decode($this->impl, $data, strlen($data)));
- $this->_post_decode();
- }
-}
-
-class Binary {
-
- public $bytes;
-
- public function __construct($bytes) {
- $this->bytes = $bytes;
- }
-
- public function __tostring() {
- return "Binary($this->bytes)";
- }
-
-}
-
-class Symbol {
-
- public $name;
-
- public function __construct($name) {
- $this->name = $name;
- }
-
- public function __tostring() {
- return "Symbol($this->name)";
- }
-
-}
-
-class UUID {
-
- public $bytes;
-
- public function __construct($bytes) {
- if (strlen($bytes) != 16) {
- throw new Exception("invalid argument: exactly 16 bytes required");
- }
- $this->bytes = $bytes;
- }
-
- public function __tostring() {
- $b = $this->bytes;
- return sprintf("UUID(%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
- ord($b[0]), ord($b[1]), ord($b[2]), ord($b[3]),
- ord($b[4]), ord($b[5]), ord($b[6]), ord($b[7]), ord($b[8]), ord($b[9]),
- ord($b[10]), ord($b[11]), ord($b[12]), ord($b[13]), ord($b[14]), ord($b[15]));
- }
-
-}
-
-class PList {
-
- public $elements;
-
- public function __construct() {
- $this->elements = func_get_args();
- }
-
- public function __tostring() {
- return "PList(" . implode(", ", $this->elements) . ")";
- }
-
-}
-
-class Char {
-
- public $codepoint;
-
- public function __construct($codepoint) {
- $this->codepoint = $codepoint;
- }
-
- public function __tostring() {
- return "Char($this->codepoint)";
- }
-
-}
-
-class Described {
-
- public $descriptor;
- public $value;
-
- public function __construct($descriptor, $value) {
- $this->descriptor = $descriptor;
- $this->value = $value;
- }
-
- public function __tostring() {
- return "Described($this->descriptor, $this->value)";
- }
-
-}
-
-class DataException extends ProtonException {}
-
-class Data {
-
- const NULL = PN_NULL;
- const BOOL = PN_BOOL;
- const UBYTE = PN_UBYTE;
- const BYTE = PN_BYTE;
- const USHORT = PN_USHORT;
- const SHORT = PN_SHORT;
- const UINT = PN_UINT;
- const INT = PN_INT;
- const CHAR = PN_CHAR;
- const ULONG = PN_ULONG;
- const LONG = PN_LONG;
- const TIMESTAMP = PN_TIMESTAMP;
- const FLOAT = PN_FLOAT;
- const DOUBLE = PN_DOUBLE;
- const DECIMAL32 = PN_DECIMAL32;
- const DECIMAL64 = PN_DECIMAL64;
- const DECIMAL128 = PN_DECIMAL128;
- const UUID = PN_UUID;
- const BINARY = PN_BINARY;
- const STRING = PN_STRING;
- const SYMBOL = PN_SYMBOL;
- const DESCRIBED = PN_DESCRIBED;
- const PARRAY = PN_ARRAY;
- const PLIST = PN_LIST;
- const MAP = PN_MAP;
-
- private $impl;
- private $free;
-
- public function __construct($capacity=16) {
- if (is_int($capacity)) {
- $this->impl = pn_data($capacity);
- $this->free = true;
- } else {
- $this->impl = $capacity;
- $this->free = false;
- }
- }
-
- public function __destruct() {
- if ($this->free)
- pn_data_free($this->impl);
- }
-
- public function _check($value) {
- if ($value < 0) {
- $exc = code2exc($value);
- if ($exc == null) $exc = "DataException";
- throw new $exc("[$value]");
- } else {
- return $value;
- }
- }
-
- public function clear() {
- pn_data_clear($this->impl);
- }
-
- public function rewind() {
- pn_data_rewind($this->impl);
- }
-
- public function next() {
- $found = pn_data_next($this->impl);
- if ($found)
- return $this->type();
- else
- return null;
- }
-
- public function prev() {
- $found = pn_data_prev($this->impl);
- if ($found)
- return $this->type();
- else
- return null;
- }
-
- public function enter() {
- return pn_data_enter($this->impl);
- }
-
- public function exit_() {
- return pn_data_exit($this->impl);
- }
-
- public function type() {
- $dtype = pn_data_type($this->impl);
- if ($dtype == -1)
- return null;
- else
- return $dtype;
- }
-
- public function encode() {
- $size = 1024;
- while (true) {
- list($cd, $enc) = pn_data_encode($this->impl, $size);
- if ($cd == PN_OVERFLOW)
- $size *= 2;
- else if ($cd >= 0)
- return $enc;
- else
- $this->_check($cd);
- }
- }
-
- public function decode($encoded) {
- return $this->_check(pn_data_decode($this->impl, $encoded));
- }
-
- public function put_list() {
- $this->_check(pn_data_put_list($this->impl));
- }
-
- public function put_map() {
- $this->_check(pn_data_put_map($this->impl));
- }
-
- public function put_array($described, $element_type) {
- $this->_check(pn_data_put_array($this->impl, $described, $element_type));
- }
-
- public function put_described() {
- $this->_check(pn_data_put_described($this->impl));
- }
-
- public function put_null() {
- $this->_check(pn_data_put_null($this->impl));
- }
-
- public function put_bool($b) {
- $this->_check(pn_data_put_bool($this->impl, $b));
- }
-
- public function put_ubyte($ub) {
- $this->_check(pn_data_put_ubyte($this->impl, $ub));
- }
-
- public function put_byte($b) {
- $this->_check(pn_data_put_byte($this->impl, $b));
- }
-
- public function put_ushort($us) {
- $this->_check(pn_data_put_ushort($this->impl, $us));
- }
-
- public function put_short($s) {
- $this->_check(pn_data_put_short($this->impl, $s));
- }
-
- public function put_uint($ui) {
- $this->_check(pn_data_put_uint($this->impl, $ui));
- }
-
- public function put_int($i) {
- $this->_check(pn_data_put_int($this->impl, $i));
- }
-
- public function put_char($c) {
- if ($c instanceof Char) {
- $c = $c->codepoint;
- } else {
- $c = ord($c);
- }
- $this->_check(pn_data_put_char($this->impl, $c));
- }
-
- public function put_ulong($ul) {
- $this->_check(pn_data_put_ulong($this->impl, $ul));
- }
-
- public function put_long($l) {
- $this->_check(pn_data_put_long($this->impl, $l));
- }
-
- public function put_timestamp($t) {
- $this->_check(pn_data_put_timestamp($this->impl, $t));
- }
-
- public function put_float($f) {
- $this->_check(pn_data_put_float($this->impl, $f));
- }
-
- public function put_double($d) {
- $this->_check(pn_data_put_double($this->impl, $d));
- }
-
- public function put_decimal32($d) {
- $this->_check(pn_data_put_decimal32($this->impl, $d));
- }
-
- public function put_decimal64($d) {
- $this->_check(pn_data_put_decimal64($this->impl, $d));
- }
-
- public function put_decimal128($d) {
- $this->_check(pn_data_put_decimal128($this->impl, $d));
- }
-
- public function put_uuid($u) {
- if ($u instanceof UUID) {
- $u = $u->bytes;
- }
- $this->_check(pn_data_put_uuid($this->impl, $u));
- }
-
- public function put_binary($b) {
- if ($b instanceof Binary) {
- $b = $b->bytes;
- }
- $this->_check(pn_data_put_binary($this->impl, $b));
- }
-
- public function put_string($s) {
- $this->_check(pn_data_put_string($this->impl, $s));
- }
-
- public function put_symbol($s) {
- if ($s instanceof Symbol) {
- $s = $s->name;
- }
- $this->_check(pn_data_put_symbol($this->impl, $s));
- }
-
- public function get_list() {
- return pn_data_get_list($this->impl);
- }
-
- public function get_map() {
- return pn_data_get_map($this->impl);
- }
-
- public function get_array() {
- $count = pn_data_get_array($this->impl);
- $described = pn_data_is_array_described($this->impl);
- $type = pn_data_get_array_type($this->impl);
- if ($type == -1)
- $type = null;
- return array($count, $described, $type);
- }
-
- public function is_described() {
- return pn_data_is_described($this->impl);
- }
-
- public function is_null() {
- $this->_check(pn_data_get_null($this->impl));
- }
-
- public function get_bool() {
- return pn_data_get_bool($this->impl);
- }
-
- public function get_ubyte() {
- return pn_data_get_ubyte($this->impl);
- }
-
- public function get_byte() {
- return pn_data_get_byte($this->impl);
- }
-
- public function get_ushort() {
- return pn_data_get_ushort($this->impl);
- }
-
- public function get_short() {
- return pn_data_get_short($this->impl);
- }
-
- public function get_uint() {
- return pn_data_get_uint($this->impl);
- }
-
- public function get_int() {
- return pn_data_get_int($this->impl);
- }
-
- public function get_char() {
- return new Char(pn_data_get_char($this->impl));
- }
-
- public function get_ulong() {
- return pn_data_get_ulong($this->impl);
- }
-
- public function get_long() {
- return pn_data_get_long($this->impl);
- }
-
- public function get_timestamp() {
- return pn_data_get_timestamp($this->impl);
- }
-
- public function get_float() {
- return pn_data_get_float($this->impl);
- }
-
- public function get_double() {
- return pn_data_get_double($this->impl);
- }
-
- # XXX: need to convert
- public function get_decimal32() {
- return pn_data_get_decimal32($this->impl);
- }
-
- # XXX: need to convert
- public function get_decimal64() {
- return pn_data_get_decimal64($this->impl);
- }
-
- # XXX: need to convert
- public function get_decimal128() {
- return pn_data_get_decimal128($this->impl);
- }
-
- public function get_uuid() {
- if (pn_data_type($this->impl) == Data::UUID)
- return new UUID(pn_data_get_uuid($this->impl));
- else
- return null;
- }
-
- public function get_binary() {
- return new Binary(pn_data_get_binary($this->impl));
- }
-
- public function get_string() {
- return pn_data_get_string($this->impl);
- }
-
- public function get_symbol() {
- return new Symbol(pn_data_get_symbol($this->impl));
- }
-
- public function copy($src) {
- $this->_check(pn_data_copy($this->impl, $src->impl));
- }
-
- public function format() {
- $sz = 16;
- while (true) {
- list($err, $result) = pn_data_format($this->impl, $sz);
- if ($err == PN_OVERFLOW) {
- $sz *= 2;
- continue;
- } else {
- $this->_check($err);
- return $result;
- }
- }
- }
-
- public function dump() {
- pn_data_dump($this->impl);
- }
-
- public function get_null() {
- return null;
- }
-
- public function get_php_described() {
- if ($this->enter()) {
- try {
- $this->next();
- $descriptor = $this->get_object();
- $this->next();
- $value = $this->get_object();
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
- return new Described($descriptor, $value);
- }
- }
-
- public function get_php_array() {
- if ($this->enter()) {
- try {
- $result = array();
- while ($this->next()) {
- $result[] = $this->get_object();
- }
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
- return $result;
- }
- }
-
- public function put_php_list($lst) {
- $this->put_list();
- $this->enter();
- try {
- foreach ($lst->elements as $e) {
- $this->put_object($e);
- }
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
- }
-
- public function get_php_list() {
- if ($this->enter()) {
- try {
- $result = new PList();
- while ($this->next()) {
- $result->elements[] = $this->get_object();
- }
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
-
- return $result;
- }
- }
-
- public function put_php_map($ary) {
- $this->put_map();
- $this->enter();
- try {
- foreach ($ary as $k => $v) {
- $this->put_object($k);
- $this->put_object($v);
- }
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
- }
-
- public function get_php_map() {
- if ($this->enter()) {
- try {
- $result = array();
- while ($this->next()) {
- $k = $this->get_object();
- switch ($this->type()) {
- case Data::BINARY:
- $k = $k->bytes;
- break;
- case Data::SYMBOL:
- $k = $k->name;
- break;
- case Data::STRING:
- case Data::UBYTE:
- case Data::BYTE:
- case Data::USHORT:
- case Data::SHORT:
- case Data::UINT:
- case Data::INT:
- case Data::ULONG:
- case Data::LONG:
- break;
- default:
- $k = "$k";
- break;
- }
- if ($this->next())
- $v = $this->get_object();
- else
- $v = null;
- $result[$k] = $v;
- }
- $this->exit_();
- } catch (Exception $e) {
- $this->exit_();
- throw $e;
- }
- return $result;
- }
- }
-
- private $put_mappings = array
- ("NULL" => "put_null",
- "boolean" => "put_bool",
- "UUID" => "put_uuid",
- "string" => "put_string",
- "Binary" => "put_binary",
- "Symbol" => "put_symbol",
- "integer" => "put_long",
- "Char" => "put_char",
- "double" => "put_double",
- "Described" => "put_php_described",
- "PList" => "put_php_list",
- "array" => "put_php_map"
- );
- private $get_mappings = array
- (Data::NULL => "get_null",
- Data::BOOL => "get_bool",
- Data::UBYTE => "get_ubyte",
- Data::BYTE => "get_byte",
- Data::USHORT => "get_ushort",
- Data::SHORT => "get_short",
- Data::UINT => "get_uint",
- Data::INT => "get_int",
- Data::CHAR => "get_char",
- Data::ULONG => "get_ulong",
- Data::LONG => "get_long",
- Data::TIMESTAMP => "get_timestamp",
- Data::FLOAT => "get_float",
- Data::DOUBLE => "get_double",
- Data::DECIMAL32 => "get_decimal32",
- Data::DECIMAL64 => "get_decimal64",
- Data::DECIMAL128 => "get_decimal128",
- Data::UUID => "get_uuid",
- Data::BINARY => "get_binary",
- Data::STRING => "get_string",
- Data::SYMBOL => "get_symbol",
- Data::DESCRIBED => "get_php_described",
- Data::PARRAY => "get_php_array",
- Data::PLIST => "get_php_list",
- Data::MAP => "get_php_map"
- );
-
- public function put_object($obj) {
- $type = gettype($obj);
- if ($type == "object") {
- $type = get_class($obj);
- }
- $putter = $this->put_mappings[$type];
- if ($putter == null)
- throw new DataException("unknown type: $type");
- $this->$putter($obj);
- }
-
- public function get_object() {
- $type = $this->type();
- if ($type == null) return null;
- $getter = $this->get_mappings[$type];
- return $this->$getter();
- }
-
-}
-
-?>
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/php/tests.php
----------------------------------------------------------------------
diff --git a/proton-c/bindings/php/tests.php b/proton-c/bindings/php/tests.php
deleted file mode 100644
index 8ae45cf..0000000
--- a/proton-c/bindings/php/tests.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/*
- *
- * 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.
- *
-*/
-
-
-include("proton.php");
-
-function round_trip($body) {
- $msg = new Message();
- $msg->inferred = true;
- $msg->durable = true;
- $msg->id = 10;
- $msg->correlation_id = "asdf";
- $msg->properties = array();
- $msg->properties["null"] = null;
- $msg->properties["boolean"] = true;
- $msg->properties["integer"] = 123;
- $msg->properties["double"] = 3.14159;
- $msg->properties["binary"] = new Binary("binary");
- $msg->properties["symbol"] = new Symbol("symbol");
- $msg->properties["uuid"] = new UUID("1234123412341234");
- $msg->properties["list"] = new PList(1, 2, 3, 4);
- $msg->properties["char"] = new Char(321);
- $msg->body = $body;
- assert($msg->id == 10);
- assert($msg->correlation_id == "asdf");
-
- $copy = new Message();
- $copy->decode($msg->encode());
- assert($copy->id == $msg->id);
- assert($copy->correlation_id == $msg->correlation_id);
- $diff = array_diff($msg->properties, $copy->properties);
- assert($copy->durable == $msg->durable);
- assert(count($diff) == 0);
- assert($copy->body == $msg->body);
-}
-
-round_trip("this is a string body");
-round_trip(new Binary("this is a binary body"));
-round_trip(new Symbol("this is a symbol body"));
-round_trip(true);
-round_trip(1234);
-round_trip(3.14159);
-round_trip(array("pi" => 3.14159, "blueberry-pi" => "yummy"));
-
-?>
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 1878d57..60f7323 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -23,7 +23,6 @@ protocol.
The proton APIs consist of the following classes:
- - L{Messenger} -- A messaging endpoint.
- L{Message} -- A class for creating and/or accessing AMQP message content.
- L{Data} -- A class for creating and/or accessing arbitrary AMQP encoded
data.
@@ -166,13 +165,6 @@ class Interrupt(ProtonException):
"""
pass
-class MessengerException(ProtonException):
- """
- The root of the messenger exception hierarchy. All exceptions
- generated by the messenger class derive from this exception.
- """
- pass
-
class MessageException(ProtonException):
"""
The MessageException class is the root of the message exception
@@ -205,600 +197,6 @@ STATUSES = {
PN_STATUS_UNKNOWN: None
}
-AUTOMATIC = Constant("AUTOMATIC")
-MANUAL = Constant("MANUAL")
-
-class Messenger(object):
- """
- The L{Messenger} class defines a high level interface for sending
- and receiving L{Messages<Message>}. Every L{Messenger} contains a
- single logical queue of incoming messages and a single logical queue
- of outgoing messages. These messages in these queues may be destined
- for, or originate from, a variety of addresses.
-
- The messenger interface is single-threaded. All methods
- except one (L{interrupt}) are intended to be used from within
- the messenger thread.
-
-
- Address Syntax
- ==============
-
- An address has the following form::
-
- [ amqp[s]:// ] [user[:password]@] domain [/[name]]
-
- Where domain can be one of::
-
- host | host:port | ip | ip:port | name
-
- The following are valid examples of addresses:
-
- - example.org
- - example.org:1234
- - amqp://example.org
- - amqps://example.org
- - example.org/incoming
- - amqps://example.org/outgoing
- - amqps://fred:trustno1@example.org
- - 127.0.0.1:1234
- - amqps://127.0.0.1:1234
-
- Sending & Receiving Messages
- ============================
-
- The L{Messenger} class works in conjunction with the L{Message} class. The
- L{Message} class is a mutable holder of message content.
-
- The L{put} method copies its L{Message} to the outgoing queue, and may
- send queued messages if it can do so without blocking. The L{send}
- method blocks until it has sent the requested number of messages,
- or until a timeout interrupts the attempt.
-
-
- >>> message = Message()
- >>> for i in range(3):
- ... message.address = "amqp://host/queue"
- ... message.subject = "Hello World %i" % i
- ... messenger.put(message)
- >>> messenger.send()
-
- Similarly, the L{recv} method receives messages into the incoming
- queue, and may block as it attempts to receive the requested number
- of messages, or until timeout is reached. It may receive fewer
- than the requested number. The L{get} method pops the
- eldest L{Message} off the incoming queue and copies it into the L{Message}
- object that you supply. It will not block.
-
-
- >>> message = Message()
- >>> messenger.recv(10):
- >>> while messenger.incoming > 0:
- ... messenger.get(message)
- ... print message.subject
- Hello World 0
- Hello World 1
- Hello World 2
-
- The blocking flag allows you to turn off blocking behavior entirely,
- in which case L{send} and L{recv} will do whatever they can without
- blocking, and then return. You can then look at the number
- of incoming and outgoing messages to see how much outstanding work
- still remains.
- """
-
- def __init__(self, name=None):
- """
- Construct a new L{Messenger} with the given name. The name has
- global scope. If a NULL name is supplied, a UUID based name will
- be chosen.
-
- @type name: string
- @param name: the name of the messenger or None
-
- """
- self._mng = pn_messenger(name)
- self._selectables = {}
-
- def __del__(self):
- """
- Destroy the L{Messenger}. This will close all connections that
- are managed by the L{Messenger}. Call the L{stop} method before
- destroying the L{Messenger}.
- """
- if hasattr(self, "_mng"):
- pn_messenger_free(self._mng)
- del self._mng
-
- def _check(self, err):
- if err < 0:
- if (err == PN_INPROGRESS):
- return
- exc = EXCEPTIONS.get(err, MessengerException)
- raise exc("[%s]: %s" % (err, pn_error_text(pn_messenger_error(self._mng))))
- else:
- return err
-
- @property
- def name(self):
- """
- The name of the L{Messenger}.
- """
- return pn_messenger_name(self._mng)
-
- def _get_certificate(self):
- return pn_messenger_get_certificate(self._mng)
-
- def _set_certificate(self, value):
- self._check(pn_messenger_set_certificate(self._mng, value))
-
- certificate = property(_get_certificate, _set_certificate,
- doc="""
-Path to a certificate file for the L{Messenger}. This certificate is
-used when the L{Messenger} accepts or establishes SSL/TLS connections.
-This property must be specified for the L{Messenger} to accept
-incoming SSL/TLS connections and to establish client authenticated
-outgoing SSL/TLS connection. Non client authenticated outgoing SSL/TLS
-connections do not require this property.
-""")
-
- def _get_private_key(self):
- return pn_messenger_get_private_key(self._mng)
-
- def _set_private_key(self, value):
- self._check(pn_messenger_set_private_key(self._mng, value))
-
- private_key = property(_get_private_key, _set_private_key,
- doc="""
-Path to a private key file for the L{Messenger's<Messenger>}
-certificate. This property must be specified for the L{Messenger} to
-accept incoming SSL/TLS connections and to establish client
-authenticated outgoing SSL/TLS connection. Non client authenticated
-SSL/TLS connections do not require this property.
-""")
-
- def _get_password(self):
- return pn_messenger_get_password(self._mng)
-
- def _set_password(self, value):
- self._check(pn_messenger_set_password(self._mng, value))
-
- password = property(_get_password, _set_password,
- doc="""
-This property contains the password for the L{Messenger.private_key}
-file, or None if the file is not encrypted.
-""")
-
- def _get_trusted_certificates(self):
- return pn_messenger_get_trusted_certificates(self._mng)
-
- def _set_trusted_certificates(self, value):
- self._check(pn_messenger_set_trusted_certificates(self._mng, value))
-
- trusted_certificates = property(_get_trusted_certificates,
- _set_trusted_certificates,
- doc="""
-A path to a database of trusted certificates for use in verifying the
-peer on an SSL/TLS connection. If this property is None, then the peer
-will not be verified.
-""")
-
- def _get_timeout(self):
- t = pn_messenger_get_timeout(self._mng)
- if t == -1:
- return None
- else:
- return millis2secs(t)
-
- def _set_timeout(self, value):
- if value is None:
- t = -1
- else:
- t = secs2millis(value)
- self._check(pn_messenger_set_timeout(self._mng, t))
-
- timeout = property(_get_timeout, _set_timeout,
- doc="""
-The timeout property contains the default timeout for blocking
-operations performed by the L{Messenger}.
-""")
-
- def _is_blocking(self):
- return pn_messenger_is_blocking(self._mng)
-
- def _set_blocking(self, b):
- self._check(pn_messenger_set_blocking(self._mng, b))
-
- blocking = property(_is_blocking, _set_blocking,
- doc="""
-Enable or disable blocking behavior during L{Message} sending
-and receiving. This affects every blocking call, with the
-exception of L{work}. Currently, the affected calls are
-L{send}, L{recv}, and L{stop}.
-""")
-
- def _is_passive(self):
- return pn_messenger_is_passive(self._mng)
-
- def _set_passive(self, b):
- self._check(pn_messenger_set_passive(self._mng, b))
-
- passive = property(_is_passive, _set_passive,
- doc="""
-When passive is set to true, Messenger will not attempt to perform I/O
-internally. In this mode it is necessary to use the selectables API to
-drive any I/O needed to perform requested actions. In this mode
-Messenger will never block.
-""")
-
- def _get_incoming_window(self):
- return pn_messenger_get_incoming_window(self._mng)
-
- def _set_incoming_window(self, window):
- self._check(pn_messenger_set_incoming_window(self._mng, window))
-
- incoming_window = property(_get_incoming_window, _set_incoming_window,
- doc="""
-The incoming tracking window for the messenger. The messenger will
-track the remote status of this many incoming deliveries after they
-have been accepted or rejected. Defaults to zero.
-
-L{Messages<Message>} enter this window only when you take them into your application
-using L{get}. If your incoming window size is I{n}, and you get I{n}+1 L{messages<Message>}
-without explicitly accepting or rejecting the oldest message, then the
-message that passes beyond the edge of the incoming window will be assigned
-the default disposition of its link.
-""")
-
- def _get_outgoing_window(self):
- return pn_messenger_get_outgoing_window(self._mng)
-
- def _set_outgoing_window(self, window):
- self._check(pn_messenger_set_outgoing_window(self._mng, window))
-
- outgoing_window = property(_get_outgoing_window, _set_outgoing_window,
- doc="""
-The outgoing tracking window for the messenger. The messenger will
-track the remote status of this many outgoing deliveries after calling
-send. Defaults to zero.
-
-A L{Message} enters this window when you call the put() method with the
-message. If your outgoing window size is I{n}, and you call L{put} I{n}+1
-times, status information will no longer be available for the
-first message.
-""")
-
- def start(self):
- """
- Currently a no-op placeholder.
- For future compatibility, do not L{send} or L{recv} messages
- before starting the L{Messenger}.
- """
- self._check(pn_messenger_start(self._mng))
-
- def stop(self):
- """
- Transitions the L{Messenger} to an inactive state. An inactive
- L{Messenger} will not send or receive messages from its internal
- queues. A L{Messenger} should be stopped before being discarded to
- ensure a clean shutdown handshake occurs on any internally managed
- connections.
- """
- self._check(pn_messenger_stop(self._mng))
-
- @property
- def stopped(self):
- """
- Returns true iff a L{Messenger} is in the stopped state.
- This function does not block.
- """
- return pn_messenger_stopped(self._mng)
-
- def subscribe(self, source):
- """
- Subscribes the L{Messenger} to messages originating from the
- specified source. The source is an address as specified in the
- L{Messenger} introduction with the following addition. If the
- domain portion of the address begins with the '~' character, the
- L{Messenger} will interpret the domain as host/port, bind to it,
- and listen for incoming messages. For example "~0.0.0.0",
- "amqp://~0.0.0.0", and "amqps://~0.0.0.0" will all bind to any
- local interface and listen for incoming messages with the last
- variant only permitting incoming SSL connections.
-
- @type source: string
- @param source: the source of messages to subscribe to
- """
- sub_impl = pn_messenger_subscribe(self._mng, source)
- if not sub_impl:
- self._check(pn_error_code(pn_messenger_error(self._mng)))
- raise MessengerException("Cannot subscribe to %s"%source)
- return Subscription(sub_impl)
-
- def put(self, message):
- """
- Places the content contained in the message onto the outgoing
- queue of the L{Messenger}. This method will never block, however
- it will send any unblocked L{Messages<Message>} in the outgoing
- queue immediately and leave any blocked L{Messages<Message>}
- remaining in the outgoing queue. The L{send} call may be used to
- block until the outgoing queue is empty. The L{outgoing} property
- may be used to check the depth of the outgoing queue.
-
- When the content in a given L{Message} object is copied to the outgoing
- message queue, you may then modify or discard the L{Message} object
- without having any impact on the content in the outgoing queue.
-
- This method returns an outgoing tracker for the L{Message}. The tracker
- can be used to determine the delivery status of the L{Message}.
-
- @type message: Message
- @param message: the message to place in the outgoing queue
- @return: a tracker
- """
- message._pre_encode()
- self._check(pn_messenger_put(self._mng, message._msg))
- return pn_messenger_outgoing_tracker(self._mng)
-
- def status(self, tracker):
- """
- Gets the last known remote state of the delivery associated with
- the given tracker.
-
- @type tracker: tracker
- @param tracker: the tracker whose status is to be retrieved
-
- @return: one of None, PENDING, REJECTED, MODIFIED, or ACCEPTED
- """
- disp = pn_messenger_status(self._mng, tracker);
- return STATUSES.get(disp, disp)
-
- def buffered(self, tracker):
- """
- Checks if the delivery associated with the given tracker is still
- waiting to be sent.
-
- @type tracker: tracker
- @param tracker: the tracker whose status is to be retrieved
-
- @return: true if delivery is still buffered
- """
- return pn_messenger_buffered(self._mng, tracker);
-
- def settle(self, tracker=None):
- """
- Frees a L{Messenger} from tracking the status associated with a given
- tracker. If you don't supply a tracker, all outgoing L{messages<Message>} up
- to the most recent will be settled.
- """
- if tracker is None:
- tracker = pn_messenger_outgoing_tracker(self._mng)
- flags = PN_CUMULATIVE
- else:
- flags = 0
- self._check(pn_messenger_settle(self._mng, tracker, flags))
-
- def send(self, n=-1):
- """
- This call will block until the indicated number of L{messages<Message>}
- have been sent, or until the operation times out. If n is -1 this call will
- block until all outgoing L{messages<Message>} have been sent. If n is 0 then
- this call will send whatever it can without blocking.
- """
- self._check(pn_messenger_send(self._mng, n))
-
- def recv(self, n=None):
- """
- Receives up to I{n} L{messages<Message>} into the incoming queue. If no value
- for I{n} is supplied, this call will receive as many L{messages<Message>} as it
- can buffer internally. If the L{Messenger} is in blocking mode, this
- call will block until at least one L{Message} is available in the
- incoming queue.
- """
- if n is None:
- n = -1
- self._check(pn_messenger_recv(self._mng, n))
-
- def work(self, timeout=None):
- """
- Sends or receives any outstanding L{messages<Message>} queued for a L{Messenger}.
- This will block for the indicated timeout.
- This method may also do I/O work other than sending and receiving
- L{messages<Message>}. For example, closing connections after messenger.L{stop}()
- has been called.
- """
- if timeout is None:
- t = -1
- else:
- t = secs2millis(timeout)
- err = pn_messenger_work(self._mng, t)
- if (err == PN_TIMEOUT):
- return False
- else:
- self._check(err)
- return True
-
- @property
- def receiving(self):
- return pn_messenger_receiving(self._mng)
-
- def interrupt(self):
- """
- The L{Messenger} interface is single-threaded.
- This is the only L{Messenger} function intended to be called
- from outside of the L{Messenger} thread.
- Call this from a non-messenger thread to interrupt
- a L{Messenger} that is blocking.
- This will cause any in-progress blocking call to throw
- the L{Interrupt} exception. If there is no currently blocking
- call, then the next blocking call will be affected, even if it
- is within the same thread that interrupt was called from.
- """
- self._check(pn_messenger_interrupt(self._mng))
-
- def get(self, message=None):
- """
- Moves the message from the head of the incoming message queue into
- the supplied message object. Any content in the message will be
- overwritten.
-
- A tracker for the incoming L{Message} is returned. The tracker can
- later be used to communicate your acceptance or rejection of the
- L{Message}.
-
- If None is passed in for the L{Message} object, the L{Message}
- popped from the head of the queue is discarded.
-
- @type message: Message
- @param message: the destination message object
- @return: a tracker
- """
- if message is None:
- impl = None
- else:
- impl = message._msg
- self._check(pn_messenger_get(self._mng, impl))
- if message is not None:
- message._post_decode()
- return pn_messenger_incoming_tracker(self._mng)
-
- def accept(self, tracker=None):
- """
- Signal the sender that you have acted on the L{Message}
- pointed to by the tracker. If no tracker is supplied,
- then all messages that have been returned by the L{get}
- method are accepted, except those that have already been
- auto-settled by passing beyond your incoming window size.
-
- @type tracker: tracker
- @param tracker: a tracker as returned by get
- """
- if tracker is None:
- tracker = pn_messenger_incoming_tracker(self._mng)
- flags = PN_CUMULATIVE
- else:
- flags = 0
- self._check(pn_messenger_accept(self._mng, tracker, flags))
-
- def reject(self, tracker=None):
- """
- Rejects the L{Message} indicated by the tracker. If no tracker
- is supplied, all messages that have been returned by the L{get}
- method are rejected, except those that have already been auto-settled
- by passing beyond your outgoing window size.
-
- @type tracker: tracker
- @param tracker: a tracker as returned by get
- """
- if tracker is None:
- tracker = pn_messenger_incoming_tracker(self._mng)
- flags = PN_CUMULATIVE
- else:
- flags = 0
- self._check(pn_messenger_reject(self._mng, tracker, flags))
-
- @property
- def outgoing(self):
- """
- The outgoing queue depth.
- """
- return pn_messenger_outgoing(self._mng)
-
- @property
- def incoming(self):
- """
- The incoming queue depth.
- """
- return pn_messenger_incoming(self._mng)
-
- def route(self, pattern, address):
- """
- Adds a routing rule to a L{Messenger's<Messenger>} internal routing table.
-
- The route procedure may be used to influence how a L{Messenger} will
- internally treat a given address or class of addresses. Every call
- to the route procedure will result in L{Messenger} appending a routing
- rule to its internal routing table.
-
- Whenever a L{Message} is presented to a L{Messenger} for delivery, it
- will match the address of this message against the set of routing
- rules in order. The first rule to match will be triggered, and
- instead of routing based on the address presented in the message,
- the L{Messenger} will route based on the address supplied in the rule.
-
- The pattern matching syntax supports two types of matches, a '%'
- will match any character except a '/', and a '*' will match any
- character including a '/'.
-
- A routing address is specified as a normal AMQP address, however it
- may additionally use substitution variables from the pattern match
- that triggered the rule.
-
- Any message sent to "foo" will be routed to "amqp://foo.com":
-
- >>> messenger.route("foo", "amqp://foo.com");
-
- Any message sent to "foobar" will be routed to
- "amqp://foo.com/bar":
-
- >>> messenger.route("foobar", "amqp://foo.com/bar");
-
- Any message sent to bar/<path> will be routed to the corresponding
- path within the amqp://bar.com domain:
-
- >>> messenger.route("bar/*", "amqp://bar.com/$1");
-
- Route all L{messages<Message>} over TLS:
-
- >>> messenger.route("amqp:*", "amqps:$1")
-
- Supply credentials for foo.com:
-
- >>> messenger.route("amqp://foo.com/*", "amqp://user:password@foo.com/$1");
-
- Supply credentials for all domains:
-
- >>> messenger.route("amqp://*", "amqp://user:password@$1");
-
- Route all addresses through a single proxy while preserving the
- original destination:
-
- >>> messenger.route("amqp://%/*", "amqp://user:password@proxy/$1/$2");
-
- Route any address through a single broker:
-
- >>> messenger.route("*", "amqp://user:password@broker/$1");
- """
- self._check(pn_messenger_route(self._mng, unicode2utf8(pattern), unicode2utf8(address)))
-
- def rewrite(self, pattern, address):
- """
- Similar to route(), except that the destination of
- the L{Message} is determined before the message address is rewritten.
-
- The outgoing address is only rewritten after routing has been
- finalized. If a message has an outgoing address of
- "amqp://0.0.0.0:5678", and a rewriting rule that changes its
- outgoing address to "foo", it will still arrive at the peer that
- is listening on "amqp://0.0.0.0:5678", but when it arrives there,
- the receiver will see its outgoing address as "foo".
-
- The default rewrite rule removes username and password from addresses
- before they are transmitted.
- """
- self._check(pn_messenger_rewrite(self._mng, unicode2utf8(pattern), unicode2utf8(address)))
-
- def selectable(self):
- return Selectable.wrap(pn_messenger_selectable(self._mng))
-
- @property
- def deadline(self):
- tstamp = pn_messenger_deadline(self._mng)
- if tstamp:
- return millis2secs(tstamp)
- else:
- return None
-
class Message(object):
"""The L{Message} class is a mutable holder of message content.
@@ -1190,15 +588,6 @@ The group-id for any replies.
self._check(err)
return result
-class Subscription(object):
-
- def __init__(self, impl):
- self._impl = impl
-
- @property
- def address(self):
- return pn_subscription_address(self._impl)
-
_DEFAULT = object()
class Selectable(Wrapper):
@@ -4291,9 +3680,7 @@ __all__ = [
"IMPLEMENTATION_LANGUAGE",
"ABORTED",
"ACCEPTED",
- "AUTOMATIC",
"PENDING",
- "MANUAL",
"REJECTED",
"RELEASED",
"MODIFIED",
@@ -4314,8 +3701,6 @@ __all__ = [
"Link",
"Message",
"MessageException",
- "Messenger",
- "MessengerException",
"ProtonException",
"VERSION_MAJOR",
"VERSION_MINOR",
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c9bb9ff/proton-c/bindings/ruby/lib/messenger/messenger.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/messenger/messenger.rb b/proton-c/bindings/ruby/lib/messenger/messenger.rb
deleted file mode 100644
index 912d159..0000000
--- a/proton-c/bindings/ruby/lib/messenger/messenger.rb
+++ /dev/null
@@ -1,703 +0,0 @@
-# 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.
-
-
-module Qpid::Proton::Messenger
- # @deprecated use {Qpid::Proton::Container}
- #
- # The +Messenger+ class defines a high level interface for
- # sending and receiving Messages. Every Messenger contains
- # a single logical queue of incoming messages and a single
- # logical queue of outgoing messages. These messages in these
- # queues may be destined for, or originate from, a variety of
- # addresses.
- #
- # The messenger interface is single-threaded. All methods
- # except one ( #interrupt ) are intended to be used from within
- # the messenger thread.
- #
- # === Sending & Receiving Messages
- #
- # The Messenger class works in conjuction with the Message class. The
- # Message class is a mutable holder of message content.
- #
- # The put method copies its Message to the outgoing queue, and may
- # send queued messages if it can do so without blocking. The send
- # method blocks until it has sent the requested number of
- # or until a timeout interrupts the attempt.
- #
- # Similarly, the recv method receives messages into the incoming
- # queue, and may block as it attempts to receive the requested number
- # of messages, or until timeout is reached. It may receive fewer
- # than the requested number. The get method pops the
- # eldest Message off the incoming queue and copies it into the Message
- # object that you supply. It will not block.
- #
- # The blocking attribute allows you to turn off blocking behavior entirely,
- # in which case send and recv will do whatever they can without
- # blocking, and then return. You can then look at the number
- # of incoming and outgoing messages to see how much outstanding work
- # still remains.
- #
- class Messenger
-
- include Qpid::Proton::Util::ErrorHandler
- include Qpid::Proton::Util::Deprecation
-
- # Creates a new +Messenger+.
- #
- # The +name+ parameter is optional. If one is not provided then
- # a unique name is generated.
- #
- # ==== Options
- #
- # * name - the name (def. nil)
- #
- def initialize(name = nil)
- deprecated Qpid::Proton::Messenger, Qpid::Proton::Container
- @impl = Cproton.pn_messenger(name)
- @selectables = {}
- ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
- end
-
- def self.finalize!(impl) # :nodoc:
- proc {
- Cproton.pn_messenger_free(impl)
- }
- end
-
- # Returns the name.
- #
- def name
- Cproton.pn_messenger_name(@impl)
- end
-
- # This property contains the password for the Messenger.private_key
- # file, or +nil+ if the file is not encrypted.
- #
- # ==== Arguments
- #
- # * password - the password
- #
- def password=(password)
- Cproton.pn_messenger_set_password(@impl, password)
- end
-
- # Returns the password property for the Messenger.private_key file.
- #
- def password
- Cproton.pn_messenger_get_password(@impl)
- end
-
- # Sets the timeout period, in milliseconds.
- #
- # A negative timeout period implies an infinite timeout.
- #
- # ==== Options
- #
- # * timeout - the timeout period
- #
- def timeout=(timeout)
- raise TypeError.new("invalid timeout: #{timeout}") if timeout.nil?
- Cproton.pn_messenger_set_timeout(@impl, timeout)
- end
-
- # Returns the timeout period
- #
- def timeout
- Cproton.pn_messenger_get_timeout(@impl)
- end
-
- # Returns true if blocking mode is enabled.
- #
- # Enable or disable blocking behavior during message sending
- # and receiving. This affects every blocking call, with the
- # exception of work(). Currently, the affected calls are
- # send, recv, and stop.
- def blocking?
- Cproton.pn_messenger_is_blocking(@impl)
- end
-
- # Sets the blocking mode.
- def blocking=(blocking)
- Cproton.pn_messenger_set_blocking(@impl, blocking)
- end
-
- # Returns true if passive mode is enabled.
- #
- def passive?
- Cproton.pn_messenger_is_passive(@impl)
- end
-
- # Turns passive mode on or off.
- #
- # When set to passive mode, Messenger will not attempt to perform I/O
- # operations internally. In this mode it is necesssary to use the
- # Selectable type to drive any I/O needed to perform requestioned
- # actions.
- #
- # In this mode Messenger will never block.
- #
- def passive=(mode)
- Cproton.pn_messenger_set_passive(@impl, mode)
- end
-
- def deadline
- tstamp = Cproton.pn_messenger_deadline(@impl)
- return tstamp / 1000.0 unless tstamp.nil?
- end
-
- # Reports whether an error occurred.
- #
- def error?
- !Cproton.pn_messenger_errno(@impl).zero?
- end
-
- # Returns the most recent error number.
- #
- def errno
- Cproton.pn_messenger_errno(@impl)
- end
-
- # Returns the most recent error message.
- #
- def error
- Cproton.pn_error_text(Cproton.pn_messenger_error(@impl))
- end
-
- # Clears the current error state.
- #
- def clear_error
- error = Cproton.pn_messenger_error(@impl)
- unless error.nil?
- Cproton.pn_error_clear(error)
- end
- end
-
- # For future compatibility, do not send or recv messages
- # before starting the +Messenger+.
- #
- def start
- at_exit { stop }
- Cproton.pn_messenger_start(@impl)
- end
-
- # Stops the +Messenger+, preventing it from sending or receiving
- # any more messages.
- #
- def stop
- Cproton.pn_messenger_stop(@impl)
- end
-
- # Returns true if a Messenger is in the stopped state.
- # This function does not block.
- #
- def stopped?
- Cproton.pn_messenger_stopped(@impl)
- end
-
- # Subscribes the Messenger to messages originating from the
- # specified source. The source is an address as specified in the
- # Messenger introduction with the following addition. If the
- # domain portion of the address begins with the '~' character, the
- # Messenger will interpret the domain as host/port, bind to it,
- # and listen for incoming messages. For example "~0.0.0.0",
- # "amqp://~0.0.0.0" will all bind to any local interface and
- # listen for incoming messages. An address of "amqps://~0.0.0.0"
- # will only permit incoming SSL connections.
- #
- # ==== Options
- #
- # * address - the source address to be subscribe
- # * timeout - an optional time-to-live value, in seconds, for the
- # subscription
- #
- def subscribe(address, timeout=0)
- raise TypeError.new("invalid address: #{address}") if address.nil?
- subscription = Cproton.pn_messenger_subscribe_ttl(@impl, address, timeout)
- raise Qpid::Proton::ProtonError.new("Subscribe failed") if subscription.nil?
- Subscription.new(subscription)
- end
-
- # Path to a certificate file for the +Messenger+.
- #
- # This certificate is used when the +Messenger+ accepts or establishes
- # SSL/TLS connections. This property must be specified for the
- # Messenger to accept incoming SSL/TLS connections and to establish
- # client authenticated outgoing SSL/TLS connection. Non client authenticated
- # outgoing SSL/TLS connections do not require this property.
- #
- # ==== Options
- #
- # * certificate - the certificate
- #
- def certificate=(certificate)
- Cproton.pn_messenger_set_certificate(@impl, certificate)
- end
-
- # Returns the path to a certificate file.
- #
- def certificate
- Cproton.pn_messenger_get_certificate(@impl)
- end
-
- # Path to a private key file for the +Messenger+.
- #
- # The property must be specified for the +Messenger+ to accept incoming
- # SSL/TLS connections and to establish client authenticated outgoing
- # SSL/TLS connections. Non client authenticated SSL/TLS connections
- # do not require this property.
- #
- # ==== Options
- #
- # * key - the key file
- #
- def private_key=(key)
- Cproton.pn_messenger_set_private_key(@impl, key)
- end
-
- # Returns the path to a private key file.
- #
- def private_key
- Cproton.pn_messenger_get_private_key(@impl)
- end
-
- # A path to a database of trusted certificates for use in verifying the
- # peer on an SSL/TLS connection. If this property is +nil+, then the
- # peer will not be verified.
- #
- # ==== Options
- #
- # * certificates - the certificates path
- #
- def trusted_certificates=(certificates)
- Cproton.pn_messenger_set_trusted_certificates(@impl,certificates)
- end
-
- # The path to the databse of trusted certificates.
- #
- def trusted_certificates
- Cproton.pn_messenger_get_trusted_certificates(@impl)
- end
-
- # Places the content contained in the message onto the outgoing
- # queue of the Messenger.
- #
- # This method will never block, however it will send any unblocked
- # Messages in the outgoing queue immediately and leave any blocked
- # Messages remaining in the outgoing queue.
- # The send call may then be used to block until the outgoing queue
- # is empty. The outgoing attribute may be used to check the depth
- # of the outgoing queue.
- #
- # ==== Options
- #
- # * message - the message
- #
- def put(message)
- if message.nil?
- raise TypeError.new("invalid message: #{message}")
- end
- unless message.kind_of?(Qpid::Proton::Message)
- raise ::ArgumentError.new("invalid message type: #{message.class}")
- end
- # encode the message first
- message.pre_encode
- perform_put(message)
- return outgoing_tracker
- end
-
- private
-
- def perform_put(message) # :nodoc:
- Cproton.pn_messenger_put(@impl, message.impl)
- end
-
- public
-
-
- # This call will block until the indicated number of messages
- # have been sent, or until the operation times out.
- # If n is -1 this call will block until all outgoing messages
- # have been sent. If n is 0 then this call will send whatever
- # it can without blocking.
- #
- def send(n = -1)
- Cproton.pn_messenger_send(@impl, n)
- end
-
- # Moves the message from the head of the incoming message queue into
- # the supplied message object. Any content in the supplied message
- # will be overwritten.
- # A tracker for the incoming Message is returned. The tracker can
- # later be used to communicate your acceptance or rejection of the
- # Message.
- #
- # If no message is provided in the argument, then one is created. In
- # either case, the one returned will be the fetched message.
- #
- # ==== Options
- #
- # * msg - the (optional) +Message+ instance to be used
- #
- def get(msg = nil)
- msg_impl = nil
- if msg.nil? then
- msg_impl = nil
- else
- msg_impl = msg.impl
- end
- perform_get(msg_impl)
- msg.post_decode unless msg.nil?
- return incoming_tracker
- end
-
- private
-
- def perform_get(msg) # :nodoc:
- Cproton.pn_messenger_get(@impl, msg)
- end
-
- public
-
- # Receives up to limit messages into the incoming queue. If no value
- # for limit is supplied, this call will receive as many messages as it
- # can buffer internally. If the Messenger is in blocking mode, this
- # call will block until at least one Message is available in the
- # incoming queue.
- #
- # Options ====
- #
- # * limit - the maximum number of messages to receive
- #
- def receive(limit = -1)
- Cproton.pn_messenger_recv(@impl, limit)
- end
-
- # Returns true if the messenger is currently receiving data.
- def receiving?
- Cproton.pn_messenger_receiving(@impl)
- end
-
- # Attempts interrupting of the messenger thread.
- #
- # The Messenger interface is single-threaded, and this is the only
- # function intended to be called from outside of is thread.
- #
- # Call this from a non-Messenger thread to interrupt it while it
- # is blocking. This will cause a ::InterruptError to be raised.
- #
- # If there is no currently blocking call, then the next blocking
- # call will be affected, even if it is within the same thread that
- # originated the interrupt.
- #
- def interrupt
- Cproton.pn_messenger_interrupt(@impl)
- end
-
- # Sends or receives any outstanding messages queued for a Messenger.
- #
- # This will block for the indicated timeout. This method may also do I/O
- # other than sending and receiving messages. For example, closing
- # connections after stop() has been called.
- #
- def work(timeout=-1)
- err = Cproton.pn_messenger_work(@impl, timeout)
- if (err == Cproton::PN_TIMEOUT) then
- return false
- else
- check_for_error(err)
- return true
- end
- end
-
- # Returns the number messages in the outgoing queue that have not been
- # transmitted.
- #
- def outgoing
- Cproton.pn_messenger_outgoing(@impl)
- end
-
- # Returns the number of messages in the incoming queue that have not
- # been retrieved.
- #
- def incoming
- Cproton.pn_messenger_incoming(@impl)
- end
-
- # Adds a routing rule to the Messenger's internal routing table.
- #
- # The route procedure may be used to influence how a Messenger will
- # internally treat a given address or class of addresses. Every call
- # to the route procedure will result in Messenger appending a routing
- # rule to its internal routing table.
- #
- # Whenever a Message is presented to a Messenger for delivery, it
- # will match the address of this message against the set of routing
- # rules in order. The first rule to match will be triggered, and
- # instead of routing based on the address presented in the message,
- # the Messenger will route based on the address supplied in the rule.
- #
- # The pattern matching syntax supports two types of matches, a '%'
- # will match any character except a '/', and a '*' will match any
- # character including a '/'.
- #
- # A routing address is specified as a normal AMQP address, however it
- # may additionally use substitution variables from the pattern match
- # that triggered the rule.
- #
- # ==== Arguments
- #
- # * pattern - the address pattern
- # * address - the target address
- #
- # ==== Examples
- #
- # # route messages sent to foo to the destionaty amqp://foo.com
- # messenger.route("foo", "amqp://foo.com")
- #
- # # any message to foobar will be routed to amqp://foo.com/bar
- # messenger.route("foobar", "amqp://foo.com/bar")
- #
- # # any message to bar/<path> will be routed to the same path within
- # # the amqp://bar.com domain
- # messenger.route("bar/*", "amqp://bar.com/$1")
- #
- # # route all Message objects over TLS
- # messenger.route("amqp:*", "amqps:$1")
- #
- # # supply credentials for foo
- # messenger.route("amqp://foo.com/*", "amqp://user:password@foo.com/$1")
- #
- # # supply credentials for all domains
- # messenger.route("amqp://*", "amqp://user:password@$1")
- #
- # # route all addresses through a single proxy while preserving the
- # # original destination
- # messenger.route("amqp://%$/*", "amqp://user:password@proxy/$1/$2")
- #
- # # route any address through a single broker
- # messenger.route("*", "amqp://user:password@broker/$1")
- #
- def route(pattern, address)
- Cproton.pn_messenger_route(@impl, pattern, address)
- end
-
- # Similar to #route, except that the destination of
- # the Message is determined before the message address is rewritten.
- #
- # The outgoing address is only rewritten after routing has been
- # finalized. If a message has an outgoing address of
- # "amqp://0.0.0.0:5678", and a rewriting rule that changes its
- # outgoing address to "foo", it will still arrive at the peer that
- # is listening on "amqp://0.0.0.0:5678", but when it arrives there,
- # the receiver will see its outgoing address as "foo".
- #
- # The default rewrite rule removes username and password from addresses
- # before they are transmitted.
- #
- # ==== Arguments
- #
- # * pattern - the outgoing address
- # * address - the target address
- #
- def rewrite(pattern, address)
- Cproton.pn_messenger_rewrite(@impl, pattern, address)
- end
-
- def selectable
- impl = Cproton.pn_messenger_selectable(@impl)
-
- # if we don't have any selectables, then return
- return nil if impl.nil?
-
- fd = Cproton.pn_selectable_get_fd(impl)
-
- selectable = @selectables[fd]
- if selectable.nil?
- selectable = Selectable.new(self, impl)
- @selectables[fd] = selectable
- end
- return selectable
- end
-
- # Returns a +Tracker+ for the message most recently sent via the put
- # method.
- #
- def outgoing_tracker
- impl = Cproton.pn_messenger_outgoing_tracker(@impl)
- return nil if impl == -1
- Tracker.new(impl)
- end
-
- # Returns a +Tracker+ for the most recently received message.
- #
- def incoming_tracker
- impl = Cproton.pn_messenger_incoming_tracker(@impl)
- return nil if impl == -1
- Tracker.new(impl)
- end
-
- # Signal the sender that you have acted on the Message
- # pointed to by the tracker. If no tracker is supplied,
- # then all messages that have been returned by the get
- # method are accepted, except those that have already been
- # auto-settled by passing beyond your incoming window size.
- #
- # ==== Options
- #
- # * tracker - the tracker
- #
- def accept(tracker = nil)
- raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
- if tracker.nil? then
- tracker = self.incoming_tracker
- flag = Cproton::PN_CUMULATIVE
- else
- flag = 0
- end
- Cproton.pn_messenger_accept(@impl, tracker.impl, flag)
- end
-
- # Rejects the incoming message identified by the tracker.
- # If no tracker is supplied, all messages that have been returned
- # by the get method are rejected, except those that have already
- # been auto-settled by passing beyond your outgoing window size.
- #
- # ==== Options
- #
- # * tracker - the tracker
- #
- def reject(tracker)
- raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
- if tracker.nil? then
- tracker = self.incoming_tracker
- flag = Cproton::PN_CUMULATIVE
- else
- flag = 0
- end
- Cproton.pn_messenger_reject(@impl, tracker.impl, flag)
- end
-
- # Gets the last known remote state of the delivery associated with
- # the given tracker, as long as the Message is still within your
- # outgoing window. (Also works on incoming messages that are still
- # within your incoming queue. See TrackerStatus for details on the
- # values returned.
- #
- # ==== Options
- #
- # * tracker - the tracker
- #
- def status(tracker)
- raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
- TrackerStatus.by_value(Cproton.pn_messenger_status(@impl, tracker.impl))
- end
-
- # Frees a Messenger from tracking the status associated
- # with a given tracker. If you don't supply a tracker, all
- # outgoing messages up to the most recent will be settled.
- #
- # ==== Options
- #
- # * tracker - the tracker
- #
- # ==== Examples
- #
- def settle(tracker)
- raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
- if tracker.nil? then
- tracker = self.incoming_tracker
- flag = Cproton::PN_CUMULATIVE
- else
- flag = 0
- end
- Cproton.pn_messenger_settle(@impl, tracker.impl, flag)
- end
-
- # Sets the incoming window.
- #
- # The Messenger will track the remote status of this many incoming
- # deliveries after they have been accepted or rejected.
- #
- # Messages enter this window only when you take them into your application
- # using get(). If your incoming window size is n, and you get n+1 messages
- # without explicitly accepting or rejecting the oldest message, then the
- # message that passes beyond the edge of the incoming window will be
- # assigned the default disposition of its link.
- #
- # ==== Options
- #
- # * window - the window size
- #
- def incoming_window=(window)
- raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
- Cproton.pn_messenger_set_incoming_window(@impl, window)
- end
-
- # Returns the incoming window.
- #
- def incoming_window
- Cproton.pn_messenger_get_incoming_window(@impl)
- end
-
- # Sets the outgoing window.
- #
- # The Messenger will track the remote status of this many outgoing
- # deliveries after calling send.
- # A Message enters this window when you call the put() method with the
- # message. If your outgoing window size is n, and you call put n+1
- # times, status information will no longer be available for the
- # first message.
- #
- # ==== Options
- #
- # * window - the window size
- #
- def outgoing_window=(window)
- raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
- Cproton.pn_messenger_set_outgoing_window(@impl, window)
- end
-
- # Returns the outgoing window.
- #
- def outgoing_window
- Cproton.pn_messenger_get_outgoing_window(@impl)
- end
-
- # Unregisters a selectable object.
- def unregister_selectable(fileno) # :nodoc:
- @selectables.delete(fileno)
- end
-
- private
-
- def valid_tracker?(tracker)
- !tracker.nil? && tracker.is_a?(Tracker)
- end
-
- def valid_window?(window)
- !window.nil? && window.is_a?(Numeric)
- end
-
- can_raise_error [:send, :receive, :password=, :start, :stop,
- :perform_put, :perform_get, :interrupt,
- :route, :rewrite, :accept, :reject,
- :incoming_window=, :outgoing_window=]
-
- end
-end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org