Previous Topic

Next Topic

Book Contents

Book Index

UDP Connection Factory Service

Represents a connection factory for the OSGi communication model (described in the OSGi IO Connector Service Specification) for creating connections over the datagram scheme.

Overview

This service publishes the org.osgi.service.io.ConnectionFactory interface and represents a connection factory for the OSGi communication model, described in the OSGi IO Connector Service Specification. It is used by the OSGi Connector Service (exported by the OSGi Connector Bundle or by the System Bundle, depending on the version of the framework) for creating connections over the datagram scheme.

The datagram scheme provides UDP-based connections using the standard Java platform API for UDP sockets (contained in the java.net package: DatagramSocket, DatagramPacket, etc.). It supports connections for sending and/or for receiving.

Each created connection implements two interfaces: javax.microedition.io.DatagramConnection, which is a subinterface of Connection, and ConnectionNotifier, which registers listeners for sending connections. A connection also extends java.util.Dictionary. The Dictionary is used to store connection-related properties (described later).

It is not obligatory for both parties communicating over UDP to use the UDP Connection Factory Service. As the UDP Connection Factory Service implementation simply cares to open standard UDP sockets, connection-requester applications can communicate with any UDP socket opened on the specified host. If the connection factory is unregistered, all created connections are closed.

Registering Bundle

The service is registered by OSGi UDP Connector Bundle – com.prosyst.mbs.osgi.connector.udp. The bundle wraps a connection factory implementing the datagram scheme. This scheme provides UDP based connection that can serve as an underlying layer for various protocols. It can be used by bundles which need communication with the local or remote OSGi framework.

Datagram Uniform Resource Identifiers (URIs)

All URIs processed by the UDP connection factory must start with "datagram://". There are two types of URIs: for sending and for receiving.

Some parts of the URI are case sensitive! For details, refer to RFC 2396.

Connection Properties

The Dictionary created by each connection contains the following list of properties:

Property

Sending connection

Receiving Connection

Description

local_port

available

available

The local port to which the datagram connection is bound.

address

available

not available

The address that will be used when a new datagram is created.

port

available

not available

The remote port that will be used when a new datagram is created.

timeout

optional

optional

The timeout in milliseconds. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

The UDP connection factory keeps all opened connections in a Dictionary. If the service gets unregistered, all connections are closed.

Using the Service

If you want to use the UDP Connection Factory Service as an underlying transport implementation for your connections, you must invoke the OSGi Connector Service, exported by the Connector Service Bundle, and pass a datagram URI to its open method. For more information refer to the OSGi Connector Bundle description. You can manage the created connections using the methods of the DatagramConnection and ConnectionNotifier sub-interfaces of javax.microedition.io.Connection, and their connection properties using the values stored in the connection Dictionary.