blob: d89b2b84f8e03abaddcc515c9086ba659ce05798 (
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
78
79
80
81
82
|
' **********************************************************************
'
' Copyright (c) 2003-2009 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.
'
' **********************************************************************
Imports Demo
Imports System
Imports System.Threading
Imports System.Collections
Public Class ReapThread
Public Class SessionProxyPair
Public Sub New(ByVal p As SessionPrx, ByVal s As SessionI)
proxy = p
session = s
End Sub
Public proxy As SessionPrx
Public session As SessionI
End Class
Public Sub New()
_timeout = System.TimeSpan.FromSeconds(10)
_terminated = False
_sessions = New ArrayList
End Sub
Public Sub run()
SyncLock Me
While Not _terminated
System.Threading.Monitor.Wait(Me, System.TimeSpan.FromSeconds(1))
If Not _terminated Then
Dim tmp As ArrayList = New ArrayList
For Each p As SessionProxyPair In _sessions
Try
'
' Session destruction may take time in a
' real-world example. Therefore the current time
' is computed for each iteration.
'
If System.TimeSpan.Compare(System.DateTime.Now.Subtract(p.session.timestamp()), _timeout) > 0 Then
Dim name As String = p.proxy.getName()
p.proxy.destroy()
Console.Out.Write("The session " + name)
Console.Out.WriteLine(" has timed out.")
Else
tmp.Add(p)
End If
Catch e As Ice.ObjectNotExistException
' Ignore.
End Try
_sessions = tmp
Next
End If
End While
End SyncLock
End Sub
Public Sub terminate()
SyncLock Me
_terminated = True
System.Threading.Monitor.Pulse(Me)
_sessions.Clear()
End SyncLock
End Sub
Public Sub add(ByVal proxy As SessionPrx, ByVal session As SessionI)
SyncLock Me
_sessions.Add(New SessionProxyPair(proxy, session))
End SyncLock
End Sub
Private _terminated As Boolean
Private _timeout As System.TimeSpan
Private _sessions As ArrayList
End Class
|