blob: 5da384c39fc33311e390c8d60996a16deeff0aaa [file] [log] [blame]
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +00001/*
Richard S. Hall33b07d12006-10-18 22:02:38 +00002 * $Header: /cvshome/build/org.osgi.service.wireadmin/src/org/osgi/service/wireadmin/Consumer.java,v 1.10 2006/07/11 00:54:10 hargrave Exp $
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +00003 *
Richard S. Hall33b07d12006-10-18 22:02:38 +00004 * Copyright (c) OSGi Alliance (2002, 2006). All Rights Reserved.
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +00005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.osgi.service.wireadmin;
19
20/**
21 * Data Consumer, a service that can receive udpated values from
Richard S. Hall33b07d12006-10-18 22:02:38 +000022 * {@link Producer} services.
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000023 *
24 * <p>
25 * Service objects registered under the <code>Consumer</code> interface are
26 * expected to consume values from a Producer service via a <code>Wire</code>
27 * object. A Consumer service may poll the Producer service by calling the
Richard S. Hall33b07d12006-10-18 22:02:38 +000028 * {@link Wire#poll} method. The Consumer service will also receive an updated
29 * value when called at it's {@link #updated} method. The Producer service
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000030 * should have coerced the value to be an instance of one of the types specified
Richard S. Hall33b07d12006-10-18 22:02:38 +000031 * by the {@link Wire#getFlavors} method, or one of their subclasses.
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000032 *
33 * <p>
34 * Consumer service objects must register with a <code>service.pid</code> and a
Richard S. Hall33b07d12006-10-18 22:02:38 +000035 * {@link WireConstants#WIREADMIN_CONSUMER_FLAVORS} property. It is recommended
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000036 * that Consumer service objects also register with a
37 * <code>service.description</code> property.
38 *
39 * <p>
40 * If an <code>Exception</code> is thrown by any of the <code>Consumer</code>
41 * methods, a <code>WireAdminEvent</code> of type
Richard S. Hall33b07d12006-10-18 22:02:38 +000042 * {@link WireAdminEvent#CONSUMER_EXCEPTION} is broadcast by the Wire Admin
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000043 * service.
44 *
45 * <p>
46 * Security Considerations - Data consuming bundles will require
47 * <code>ServicePermission[Consumer,REGISTER]</code>. In general, only the Wire
48 * Admin service bundle should have this permission. Thus only the Wire Admin
49 * service may directly call a Consumer service. Care must be taken in the
50 * sharing of <code>Wire</code> objects with other bundles.
51 * <p>
52 * Consumer services must be registered with their scope when they can receive
53 * different types of objects from the Producer service. The Consumer service
54 * should have <code>WirePermission</code> for each of these scope names.
55 *
Richard S. Hall33b07d12006-10-18 22:02:38 +000056 * @version $Revision: 1.10 $
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000057 */
58public interface Consumer {
59 /**
60 * Update the value. This Consumer service is called by the <code>Wire</code>
61 * object with an updated value from the Producer service.
62 *
63 * <p>
64 * Note: This method may be called by a <code>Wire</code> object prior to this
65 * object being notified that it is connected to that <code>Wire</code> object
Richard S. Hall33b07d12006-10-18 22:02:38 +000066 * (via the {@link #producersConnected} method).
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000067 * <p>
68 * When the Consumer service can receive <code>Envelope</code> objects, it
69 * must have registered all scope names together with the service object,
70 * and each of those names must be permitted by the bundle's
71 * <code>WirePermission</code>. If an <code>Envelope</code> object is delivered
72 * with the <code>updated</code> method, then the Consumer service should
73 * assume that the security check has been performed.
74 *
75 * @param wire The <code>Wire</code> object which is delivering the updated
76 * value.
77 * @param value The updated value. The value should be an instance of one of
Richard S. Hall33b07d12006-10-18 22:02:38 +000078 * the types specified by the {@link Wire#getFlavors} method.
Michael E. Rodriguez86f57b02006-03-29 21:05:08 +000079 */
80 public void updated(Wire wire, Object value);
81
82 /**
83 * Update the list of <code>Wire</code> objects to which this Consumer service
84 * is connected.
85 *
86 * <p>
87 * This method is called when the Consumer service is first registered and
88 * subsequently whenever a <code>Wire</code> associated with this Consumer
89 * service becomes connected, is modified or becomes disconnected.
90 *
91 * <p>
92 * The Wire Admin service must call this method asynchronously. This implies
93 * that implementors of Consumer can be assured that the callback will not
94 * take place during registration when they execute the registration in a
95 * synchronized method.
96 *
97 * @param wires An array of the current and complete list of <code>Wire</code>
98 * objects to which this Consumer service is connected. May be
99 * <code>null</code> if the Consumer service is not currently connected
100 * to any <code>Wire</code> objects.
101 */
102 public void producersConnected(Wire[] wires);
103}