Skip to main content
summaryrefslogtreecommitdiffstats
blob: 515cf27081763780df6eff37e1a82c047eb30940 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/****************************************************************************
 * Copyright (c) 2005, 2010 Jan S. Rellermeyer, Systems Group,
 * Department of Computer Science, ETH Zurich and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Jan S. Rellermeyer - initial API and implementation
 *    Markus Alexander Kuppe - enhancements and bug fixes
 *    Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
 *    P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
 *
*****************************************************************************/
package ch.ethz.iks.slp;

import java.util.Locale;
import ch.ethz.iks.slp.impl.SLPCore;
import ch.ethz.iks.slp.impl.StandalonePlatformAbstraction;

/**
 * The central manager for SLP interaction. Application can get a Locator for UA
 * functionality and a Advertiser for SA functionality.
 * 
 * @author Jan S. Rellermeyer, ETH Zurich
 * @since 0.1
 */
public final class ServiceLocationManager extends SLPCore {

	/**
	 * hidden default constructor.
	 */
	private ServiceLocationManager() {
	}

	public static void init() {
		if(SLPCore.platform == null) {
			SLPCore.platform = new StandalonePlatformAbstraction();
			SLPCore.init();
		}
	}
	
	/**
	 * get the refresh interval, that is the maximum over all DA's minimum
	 * update intervals.
	 * 
	 * @return the refresh interval.
	 * @throws ServiceLocationException
	 *             in case of an exception in the underlying framework.
	 */
	public static int getRefreshInterval() throws ServiceLocationException {
		return -1;
	}

	/**
	 * get a Locator to have access to the UA functionalities.
	 * 
	 * @param locale
	 *            the <code>Locale</code> for all requests.
	 * @return a <code>Locator</code> instance.
	 * @throws ServiceLocationException
	 *             in case of an exception in the underlying framework.
	 */
	public static Locator getLocator(final Locale locale)
			throws ServiceLocationException {
		init();
		if (locator != null) {
			try {
				//TODO::We have to Initialize the Multicast Socket for UA also for receiving DA Advt Messages
				return (Locator) locator.newInstance(new Object[] { locale });
			} catch (Exception e) {
				throw new ServiceLocationException(
						ServiceLocationException.INTERNAL_SYSTEM_ERROR, e
								.getMessage());
			}
		} else {
			throw new ServiceLocationException(
					ServiceLocationException.NOT_IMPLEMENTED,
					"The current configuration does not support UA functionalities.");
		}
	}

	/**
	 * get a Advertiser to have access to the SA functionalities.
	 * 
	 * @param locale
	 *            the <code>Locale</code> for all messages.
	 * @return an <code>Advertiser</code> instance.
	 * @throws ServiceLocationException
	 *             in case of an exception in the underlying framework.
	 */
	public static Advertiser getAdvertiser(final Locale locale)
			throws ServiceLocationException {
		init();
		if (advertiser != null) {
			try {
				return (Advertiser) advertiser
						.newInstance(new Object[] { locale });
			} catch (Exception e) {
				throw new ServiceLocationException(
						ServiceLocationException.INTERNAL_SYSTEM_ERROR, e
								.getMessage());
			}
		} else {
			throw new ServiceLocationException(
					ServiceLocationException.NOT_IMPLEMENTED,
					"The current configuration does not support SA functionalities.");
		}
	}
}

Back to the top