ICE 3.4.2
[php5-ice-freebsdport.git] / vb / demo / book / simple_filesystem / Server.vb
blob24385351caf642c90df458f2ea0b5eb0692b83ca
1 Imports System
2 Imports FileSystem
4 Module Server
6 Public Class Server
7 Inherits Ice.Application
9 Public Overrides Function run(ByVal args As String()) As Integer
10 ' Terminate cleanly on receipt of a signal
12 shutdownOnInterrupt()
14 ' Create an object adapter (stored in the _adapter
15 ' static members)
17 Dim adapter As Ice.ObjectAdapter = communicator().createObjectAdapterWithEndpoints( _
18 "SimpleFilesystem", "default -h 127.0.0.1 -p 10000")
19 DirectoryI._adapter = adapter
20 FileI._adapter = adapter
22 ' Create the root directory (with name "/" and no parent)
24 Dim root As DirectoryI = New DirectoryI("/", Nothing)
26 ' Create a file called "README" in the root directory
28 Dim file As FileI = New FileI("README", root)
29 Dim text As String() = New String() {"This file system contains a collection of poetry."}
30 Try
31 file.write(text)
32 Catch e As GenericError
33 Console.Error.WriteLine(e.reason)
34 End Try
36 ' Create a directory called "Coleridge"
37 ' in the root directory
39 Dim coleridge As DirectoryI = New DirectoryI("Coleridge", root)
41 ' Create a file called "Kubla_Khan"
42 ' in the Coleridge directory
44 file = New FileI("Kubla_Khan", coleridge)
45 text = New String() {"In Xanadu did Kubla Khan", _
46 "A stately pleasure-dome decree:", _
47 "Where Alph, the sacred river, ran", _
48 "Through caverns measureless to man", _
49 "Down to a sunless sea."}
50 Try
51 CType(file, FileOperationsNC_).write(text)
52 file.write(text)
53 Catch e As GenericError
54 Console.Error.WriteLine(e.reason)
55 End Try
57 ' All objects are created, allow client requests now
59 adapter.activate()
61 ' Wait until we are done
63 communicator().waitForShutdown()
65 If interrupted() Then
66 Console.Error.WriteLine(appName() & ": terminating")
67 End If
69 Return 0
70 End Function
72 End Class
74 Public Sub Main(ByVal args As String())
75 Dim app As Server = New Server
76 Environment.Exit(app.Main(args))
77 End Sub
79 End Module