Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
DistributedSearchable.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Runtime.Remoting.Lifetime;
21 using System.Text;
22 
23 namespace Lucene.Net.Distributed.Search
24 {
25  /// <summary>
26  /// An derived implementation of RemoteSearchable, DistributedSearchable provides additional
27  /// support for integration with .Net remoting objects and constructs.
28  /// </summary>
29  [Serializable]
30  public class DistributedSearchable : Lucene.Net.Search.RemoteSearchable
31  {
32 
33  private static readonly int TIME_FACTOR = 30;
34  private static int initialLeaseTime = SupportClass.AppSettings.Get("LeaseTime", -1);
35  private static TimeSpan leaseTimeSpan;
36 
37  /// <summary>
38  /// Standard constructor for DistributedSearchable
39  /// </summary>
40  /// <param name="local">Any derived Searchable object</param>
41  public DistributedSearchable(Lucene.Net.Search.Searchable local)
42  : base(local)
43  {
44  }
45 
46  // Override on lifetime service; returning NULL yields an unlimited TTL
47  /// <summary>
48  /// Override of the base LifetimeService policy for this object. This method
49  /// manages the lifetime of objects marshaled and released in remoting environments
50  /// and distributed garbage collection.
51  /// </summary>
52  /// <returns>Object of type ILease</returns>
53  public override object InitializeLifetimeService()
54  {
55  DistributedSearchable.leaseTimeSpan = new TimeSpan(0, 0, DistributedSearchable.initialLeaseTime + DistributedSearchable.TIME_FACTOR);
56  if (DistributedSearchable.initialLeaseTime == -1)
57  {
58  return null; //Permanent TTL; never get's GC'd
59  }
60  else
61  {
62  ILease oLease = (ILease) base.InitializeLifetimeService();
63  if (oLease.CurrentState == LeaseState.Initial)
64  {
65  oLease.InitialLeaseTime = TimeSpan.FromSeconds(DistributedSearchable.leaseTimeSpan.TotalSeconds);
66  oLease.RenewOnCallTime = TimeSpan.FromSeconds(DistributedSearchable.TIME_FACTOR);
67  }
68  return oLease;
69  }
70  }
71 
72  /// <summary>
73  /// Method to extend the lifetime of a DistributedSearchable object.
74  /// </summary>
75  public void Renew()
76  {
77  ILease oLease = (ILease)this.GetLifetimeService();
79  }
80 
81  /// <summary>
82  /// Retrieves the lifetime lease length composed as a TimeSpan object
83  /// </summary>
84  /// <returns>TimeSpan representing the length of the lifetime lease for this object</returns>
85  public static TimeSpan GetLeaseTimeSpan()
86  {
87  return DistributedSearchable.leaseTimeSpan;
88  }
89 
90  /// <summary>
91  /// Returns the configured number of seconds for the lifetime length of this object
92  /// </summary>
93  /// <returns>int representing the configured number of seconds for the lifetime length of this object</returns>
94  public static int GetInitialLeaseTime()
95  {
96  return DistributedSearchable.initialLeaseTime;
97  }
98 
99  }
100 }