1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 package test
.Freeze
.evictor
;
11 import test
.Freeze
.evictor
.Test
.*;
13 public final class RemoteEvictorI
extends _RemoteEvictorDisp
20 throw new RuntimeException();
24 static class Initializer
implements Freeze
.ServantInitializer
27 initialize(Ice
.ObjectAdapter adapter
, Ice
.Identity ident
, String facet
, Ice
.Object servant
)
29 if(servant
instanceof AccountI
)
31 AccountI account
= (AccountI
)servant
;
32 account
.init((Freeze
.TransactionalEvictor
)_evictor
);
34 else if(facet
.length() == 0)
36 ServantI servantImpl
= (ServantI
) ((_ServantTie
) servant
).ice_delegate();
37 servantImpl
.init(_remoteEvictor
, _evictor
);
41 ServantI servantImpl
= (ServantI
) ((_FacetTie
) servant
).ice_delegate();
42 servantImpl
.init(_remoteEvictor
, _evictor
);
46 void init(RemoteEvictorI remoteEvictor
, Freeze
.Evictor evictor
)
48 _remoteEvictor
= remoteEvictor
;
52 private RemoteEvictorI _remoteEvictor
;
53 private Freeze
.Evictor _evictor
;
56 RemoteEvictorI(Ice
.Communicator communicator
, String envName
, String category
, boolean transactional
)
62 // NOTE: COMPILERBUG: The timeout here is required for MacOS X. It shouldn't be too low since
63 // some operations can take some time to complete on slow machines.
65 _evictorAdapter
= communicator
.
66 createObjectAdapterWithEndpoints(java
.util
.UUID
.randomUUID().toString(), "default -t 60000");
68 Initializer initializer
= new Initializer();
72 _evictor
= Freeze
.Util
.createTransactionalEvictor(_evictorAdapter
, envName
, category
, null, initializer
,
77 _evictor
= Freeze
.Util
.createBackgroundSaveEvictor(_evictorAdapter
, envName
, category
, initializer
, null,
82 // Check that we can get an iterator on a non-existing facet
84 Freeze
.EvictorIterator p
= _evictor
.getIterator("foo", 1);
85 test(p
.hasNext() == false);
87 initializer
.init(this, _evictor
);
89 _evictorAdapter
.addServantLocator(_evictor
, category
);
90 _evictorAdapter
.activate();
94 setSize(int size
, Ice
.Current current
)
96 _evictor
.setSize(size
);
100 createServant(String id
, int value
, Ice
.Current current
)
101 throws AlreadyRegisteredException
, EvictorDeactivatedException
103 Ice
.Identity ident
= new Ice
.Identity();
104 ident
.category
= _category
;
106 _ServantTie tie
= new _ServantTie();
107 tie
.ice_delegate(new ServantI(tie
, this, _evictor
, value
));
110 return ServantPrxHelper
.uncheckedCast(_evictor
.add(tie
, ident
));
112 catch(Ice
.AlreadyRegisteredException e
)
114 throw new AlreadyRegisteredException();
116 catch(Ice
.ObjectAdapterDeactivatedException e
)
118 throw new EvictorDeactivatedException();
120 catch(Freeze
.EvictorDeactivatedException e
)
122 throw new EvictorDeactivatedException();
124 catch(Ice
.LocalException e
)
126 System
.out
.println("Throwing " + e
.toString());
132 getServant(String id
, Ice
.Current current
)
134 Ice
.Identity ident
= new Ice
.Identity();
135 ident
.category
= _category
;
137 return ServantPrxHelper
.uncheckedCast(_evictorAdapter
.createProxy(ident
));
141 saveNow(Ice
.Current current
)
143 if(_evictor
instanceof Freeze
.BackgroundSaveEvictor
)
145 _evictor
.getIterator("", 1);
148 // Otherwise everything is always saved
153 deactivate(Ice
.Current current
)
155 _evictorAdapter
.destroy();
156 current
.adapter
.remove(current
.adapter
.getCommunicator().stringToIdentity(_category
));
160 destroyAllServants(String facet
, Ice
.Current current
)
163 // Only for test purpose: don't use such a small value in
164 // a real application!
168 Freeze
.EvictorIterator p
= _evictor
.getIterator(facet
, batchSize
);
171 _evictor
.remove((Ice
.Identity
) p
.next());
181 private final String _envName
;
182 private String _category
;
183 private Freeze
.Evictor _evictor
;
184 private Ice
.ObjectAdapter _evictorAdapter
;