SLP-Examples-Attributes

The LiveTribe :: SLP Module

Introduction to SLP attributes

SLP allows to specify attributes for a service.
In SLP, an attribute is a key-value pair (the key is called tag) that adds information to the service itself. A set of attributes thus describes the service.
This additional information can be, for example, displayed to users, or can be used by SLP UserAgents to filter out services that do no match certain attribute expressions.

The attribute tag must always be present, and it's always a string.

The attribute value can be:

The attribute value types can be:

Attribute values can be escaped if they contain reserved characters (the reserved characters are: ( ) , \ ! < = > ~ and all the ASCII control characters, i.e. from ASCII code 0 to 31 included) using the escape sequence '\' HEXDIG HEXDIG, where the two HEXDIGs are the exadecimal representation of the character/byte in question.
For example, if your service denote a parsing service, one attribute can be 'separator=\2C', which denotes that the value of the separator tag is the comma (since 2C exadecimal is 44 decimal, which is the ASCII code for the comma, which is a reserved character).

Attributes can be specified as a string, where each attribute is enclosed in parenthesis:

(integers=1,2),(present),(description=string),(condition=true),(bytes=\FF\CA\FE\BA\BE)

Service Templates

The entity that defines a ServiceType, such as "service:jmx", should also define a list of attributes that describe that service type.
In the JMX case, the JMX expert group defined few attributes, among which:

Tag Type MultiValued Required Description
AgentName string no yes A logical name for the JMX Agent
ProtocolType string no no The connector protocol
AgentHost string yes no The list of IP addresses on which the JMX Agent is running

SLP specifies that other attributes can be added, even if they don't appear in the service template for the exposed service type; in that case, it is suggested that the tag name begins with 'x-', because, by convention, no attribute defined by the service template begins with those characters.

Attribute expressions

UserAgent can find services not only by their service type (the most common case), but also specifying an expression that is evaluated against the service attributes.
The syntax of this expression follows the LDAPv3 search filter syntax, which is ugly but simple

The expression A and B is written as:

(&(A)(B))

The expression A or B is written as:

(|(A)(B))

The expression not A is written as:

(!(A))

Operands are the usual ones: = for equal to, != for not equal to, > for greater than, >= for greater than or equal to, < for less than, <= for less than or equal to.

Globbing is supported only using the * operator, with the usual meaning of 'any number of characters'.

Expression examples:

(&(name=Foo)(quality<5))

means name=Foo and quality<5.

(&(name=F*o)(|(quality<5)(secure=*))

means any name starting with 'F' and ending with 'o' and (quality<5 or attribute secure present)

Code Examples

Advertising a service with attributes

// Create the attributes
Attributes attributes = Attributes.from("(quality=4),(saslAuthMechanisms=PLAIN,DIGEST-MD5,KERBEROS_V5)");

ServiceURL serviceURL = new ServiceURL("service:foo://host/path");
ServiceInfo serviceInfo = new ServiceInfo(serviceURL, Scopes.DEFAULT, attributes, Locale.ENGLISH.getLanguage());

ServiceAgent serviceAgent = SLP.newServiceAgent(null);
serviceAgent.register(serviceInfo);
Discovering a service using attribute filter
UserAgentClient userAgentClient = SLP.newUserAgentClient(null);
ServiceType serviceType = new ServiceType("service:foo");

String filter = "(quality>5)";
// No match: quality is not greater than 5
List<ServiceInfo> result = userAgentClient.findServices(serviceType, null, null, filter);

filter = "(|(quality>=4)(bar=*))
// Match: quality is greater or equal to 4, bar does not exist, but the expressions are in OR
result = userAgentClient.findServices(serviceType, null, null, filter);

Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

or Sign Up  

Other Features

Add Content