ICE 3.4.2
[php5-ice-freebsdport.git] / vb / demo / IceStorm / clock / Publisher.vb
blob34dc799a4e6248a9d6707a40ed9fd53c5c43a27d
1 ' **********************************************************************
3 ' Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 ' This copy of Ice is licensed to you under the terms described in the
6 ' ICE_LICENSE file included in this distribution.
8 ' **********************************************************************
10 Imports System
11 Imports Demo
13 Module ClockC
15 Class Publisher
16 Inherits Ice.Application
18 Public Overloads Overrides Function run(ByVal args() As String) As Integer
19 Dim properties As Ice.Properties = communicator().getProperties()
21 Dim proxyProperty As String = "IceStorm.TopicManager.Proxy"
22 Dim proxy As String = properties.getProperty(proxyProperty)
23 If proxy.Length = 0 Then
24 Console.Error.WriteLine("property `" & proxyProperty & "' not set")
25 Return 1
26 End If
28 Dim basePrx As Ice.ObjectPrx = communicator().propertyToProxy("IceStorm.TopicManager.Proxy")
29 Dim manager As IceStorm.TopicManagerPrx = IceStorm.TopicManagerPrxHelper.checkedCast(basePrx)
30 If manager Is Nothing Then
31 Console.Error.WriteLine("invalid proxy")
32 Return 1
33 End If
35 Dim topicName as String = "time"
36 Dim datagram as Boolean = false
37 Dim twoway as Boolean = false
38 Dim optsSet as Integer = 0
39 For i As Integer = 0 To args.Length -1
40 If args(i).Equals("--datagram") Then
41 datagram = true
42 optsSet = optsSet + 1
43 Elseif args(i).Equals("--twoway") Then
44 twoway = true
45 optsSet = optsSet + 1
46 Elseif args(i).Equals("--oneway") Then
47 optsSet = optsSet + 1
48 Elseif args(i).StartsWith("--") Then
49 usage()
50 Return 1
51 Else
52 topicName = args(i)
53 Exit For
54 End if
55 Next
57 If optsSet > 1 Then
58 usage()
59 Return 1
60 End If
63 ' Retrieve the topic.
65 Dim topic As IceStorm.TopicPrx
66 Try
67 topic = manager.retrieve(topicName)
68 Catch ex As IceStorm.NoSuchTopic
69 Try
70 topic = manager.create(topicName)
71 Catch e As IceStorm.TopicExists
72 Console.Error.WriteLine("temporary error. try again.")
73 Return 1
74 End Try
75 End Try
78 ' Get the topic's publisher object, and create a Clock proxy with
79 ' the mode specified as an argument of this application.
81 Dim publisher as Ice.ObjectPrx = topic.getPublisher()
82 If datagram Then
83 publisher = publisher.ice_datagram()
84 Elseif twoway Then
85 ' Do nothing.
86 Else ' if oneway
87 publisher = publisher.ice_oneway()
88 End If
89 Dim clock As ClockPrx = ClockPrxHelper.uncheckedCast(publisher)
91 Console.Out.WriteLine("publishing tick events. Press ^C to terminate the application.")
92 Try
93 While 1
94 clock.tick(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"))
96 System.Threading.Thread.Sleep(1000)
97 End While
98 Catch ex As Ice.CommunicatorDestroyedException
99 End Try
101 Return 0
102 End Function
104 Public Sub usage
105 Console.WriteLine("Usage: " + appName() + " [--datagram|--twoway|--oneway] [topic]")
106 End Sub
107 End Class
109 Public Sub Main(ByVal args() As String)
110 Dim app As Publisher = New Publisher
111 Dim status As Integer = app.Main(args, "config.pub")
112 System.Environment.Exit(status)
113 End Sub
114 End Module