In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve Remoting serialization and lease. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
First of all, let's talk about the problem of Remoting serialization: first, Remoting serialization is to facilitate network transmission, transforming remote objects into a form that can be transmitted over the network. Remoting serialization can be implemented in many forms: serialized to xml, serialized to binary, and so on. Of course, using serialization requires the addition of a tag [Serializable], and you can use SerializableAttribute or implement the ISerializable interface. Here is the serialized code Demo:
1: [Serializable] 2: public class SumOf3: {4: public SumOf () 5: {6:} 7: 8: public DecimalList Members = new DecimalList (); 9: 10: public decimal Sum,Avg;11: 12: public void Calculate () 13: {14: this.Sum = 0 15: foreach (decimal m in Members) 16: {17: Sum + = m 18:} 19: this.Avg = Sum / Members.Count;20: 21:} 22: 23:} 24: [Serializable] 25: public class DecimalList: List26: {27:}
Next, let's talk about the lease, which includes three aspects: the life cycle of the object, what is the lease and the renewal of the lease.
1. The life cycle of an object
Let's first understand what an object is. An object is a data structure in memory. First, if the client detects whether the server is available, then we need to verify that the remote object still exists. This is very simple, as long as we call the remote object, if the remote object is not available, there will be an exception, which means that the server is not available. It goes on to say that the server detects whether the client is available, verifies using garbage collection mechanism, and is valid only for Singleton objects and client-activated objects.
two。 What is a lease?
A lease is a time recorded on the server, after which the object will be reclaimed.
3. Renewal: in order for the object to continue to exist, a renewal must be used.
(1) implicit renewal: it occurs automatically each time a method on the remote object is called.
(2) display renewal: realized by using ILease.Renew () method.
(3) initiating the lease: the lease manager automatically renews the contract. ILease.Register ()
Lease configuration: InitialLeaseTime lease time, default value is 300. The default value of RenewOnCallTime check time is 120. The default value for SponsorshipTimeout expiration time is 120. The default value of LeaseManagerPollTime lease manager's departure time is 10
How to display lease information:
1: ILease lease = (ILease) obj.GetLifetimeService (); 2: 3: if (lease! = null) 4: {5: Console.WriteLine ("Lease Configuration:"); 6: Console.WriteLine ("InitialLeaseTime:" + 7: lease.InitialLeaseTime) 8: Console.WriteLine ("RenewOnCallTime:" + 9: lease.RenewOnCallTime); 10: Console.WriteLine ("SponsorshipTimeout:" + 11: lease.SponsorshipTimeout); 12: Console.WriteLine (lease.CurrentLeaseTime); 13:}
How to configure lease information:
1 code mode
1: public override Object InitializeLifetimeService () 2: {3: 4: ILease lease = (ILease) base.InitializeLifetimeService () 5: / / Normally, the initial lease time would be much longer.6: / / It is shortened here for demonstration purposes.7: if (lease.CurrentState = = LeaseState.Initial) 8: {9: lease.InitialLeaseTime = TimeSpan.FromSeconds (3); 10: lease.SponsorshipTimeout = TimeSpan.FromSeconds (10) 11: lease.RenewOnCallTime = TimeSpan.FromSeconds (2); 12:} 13: return lease;14:} 2 configuration file mode
On "how to achieve Remoting serialization and lease" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.