KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > simpl > HostnameInstanceIdGenerator


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17 package org.quartz.simpl;
18
19 import java.net.InetAddress JavaDoc;
20
21 import org.quartz.SchedulerException;
22 import org.quartz.spi.InstanceIdGenerator;
23
24 /**
25  * <p>
26  * <code>InstanceIdGenerator</code> that names the scheduler instance using
27  * just the machine hostname.
28  * </p>
29  *
30  * <p>
31  * This class is useful when you know that your scheduler instance will be the
32  * only one running on a particular machine. Each time the scheduler is
33  * restarted, it will get the same instance id as long as the machine is not
34  * renamed.
35  * </p>
36  *
37  * @see InstanceIdGenerator
38  * @see SimpleInstanceIdGenerator
39  */

40 public class HostnameInstanceIdGenerator implements InstanceIdGenerator {
41     public String JavaDoc generateInstanceId() throws SchedulerException {
42         try {
43             return InetAddress.getLocalHost().getHostName();
44         } catch (Exception JavaDoc e) {
45             throw new SchedulerException("Couldn't get host name!", e);
46         }
47     }
48 }
Popular Tags