0

I have an OSGi bundle which is using two services through DS, A and B.

B service is using internally Apache's HttpClient.

My question is, when should I shutdown the HttpClient's ConnectionManager, I tried to do it inside the "unbind" method for service B but it won't work because having the unbind method being called does not mean having the instance destroyed so the same instance could be rebinded and therefore my following requests would fail because ConnectionManager was shutdown.

Hope someone could bring some light on HttpClient usage within OSGi environments.

Colin 't Hart
  • 7,372
  • 3
  • 28
  • 51
PizergSensing
  • 203
  • 3
  • 13

2 Answers2

1

Just remark. You might want to use HttpClientBuilderFactory provided by HttpClient OSGi bundle. Connection pools allocated by the factory will be automatically shutdown / deallocated by the OSGi container.

ok2c
  • 26,450
  • 5
  • 63
  • 71
  • That is the nice thing about OSGi, the providers of the service can very easily ensure cleanup when their clients disappear. Nice work. – Peter Kriens Oct 10 '13 at 06:33
0

Is B itself a DS component? If so, you can clean up during B's deactivate method call. If B is a not a DS component, but a service registered using the raw service API, you can use a ServiceFactory when registering the service. Then when a consumers releases the service, your implementation of ServiceFactory.ungetService will be called and you can clean up there.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27