HttpStateCache.jvm.cs 681 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections;
  3. using mainsoft.apache.commons.httpclient;
  4. namespace System.Net
  5. {
  6. class HttpStateCache
  7. {
  8. private static readonly int MAX_SIZE = 30;
  9. private Stack _states;
  10. private int _currentSize;
  11. internal HttpStateCache()
  12. {
  13. _states = new Stack(20);
  14. }
  15. internal HttpState GetHttpState()
  16. {
  17. lock(this)
  18. {
  19. if(_states.Count > 0)
  20. return (HttpState) _states.Pop();
  21. }
  22. return new HttpState();
  23. }
  24. internal void ReleaseHttpState(HttpState state)
  25. {
  26. lock(this)
  27. {
  28. if(_states.Count < MAX_SIZE)
  29. {
  30. state.clear();
  31. _states.Push(state);
  32. }
  33. }
  34. }
  35. }
  36. }