summaryrefslogtreecommitdiff
path: root/java/demo/IceStorm/clock/Publisher.java
blob: 4ae1d0a70244b5f84fa99eac243d6712f6d898ae (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

import Demo.*;

public class Publisher extends Ice.Application
{
    public int
    run(String[] args)
    {
        Ice.Properties properties = communicator().getProperties();
        final String proxyProperty = "IceStorm.TopicManager.Proxy";
        String proxy = properties.getProperty(proxyProperty);
        if(proxy.length() == 0)
        {
            System.err.println("property `" + proxyProperty + "' not set");
            return 1;
        }

	Ice.ObjectPrx base = communicator().stringToProxy(proxy);
        IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(base);
        if(manager == null)
        {
            System.err.println("invalid proxy");
            return 1;
        }

	//
	// Retrieve the topic named "time".
	//
	IceStorm.TopicPrx topic;
	try
	{
	    topic = manager.retrieve("time");
	}
	catch(IceStorm.NoSuchTopic e)
	{
	    System.err.println(e + "name: " + e.name);
	    return 1;
	}
	assert(topic != null);

	//
	// Get the topic's publisher object, verify that it supports
	// the Clock type, and create a oneway Clock proxy (for efficiency
	// reasons).
	//
        Ice.ObjectPrx obj = topic.getPublisher();
        if(!obj.ice_isDatagram())
        {
            obj = obj.ice_oneway();
        }
        ClockPrx clock = ClockPrxHelper.uncheckedCast(obj);

        System.out.println("publishing 10 tick events");
        for(int i = 0; i < 10; ++i)
        {
            clock.tick();
        }

        return 0;
    }

    public static void
    main(String[] args)
    {
        Publisher app = new Publisher();
        int status = app.main("Publisher", args, "config");
        System.exit(status);
    }
}