In my application I have class which extend wicket model and override finalized method(just delete file which is generated asynchronous). Problem is that finalized method is called immediately after wicket page is loaded for the first time and then once more
public class TournamentFileReadOnlyModel<I> extends AbstractReadOnlyModel<File> {
private static final long serialVersionUID = 1L;
private CallableService callableService;
private String uuid;
public TournamentFileReadOnlyModel(CallableService callableService, I input,
Class<? extends AbstractPdfCallable<I>> callableClass) {
this.uuid = UUID.randomUUID().toString();
this.callableService = callableService;
callableService.createFile(uuid, WicketApplication.getFilesPath(), input, callableClass);
}
@Override
public File getObject() {
return callableService.getFile(uuid);
}
@Override
protected void finalize() throws Throwable {
super.finalize();
callableService.finalizeFile(uuid);
}
}
I created link with this model:
private void addPrintGroupButton() {
add(new DownloadModelLink("printGroup", new TournamentFileReadOnlyModel<GroupPageDto>(callableService,
groupPageDto, GroupPdfCallable.class)));
}
log:
time is called for me with no reason because I just load web page and still have reference for model
17:50:45.493 [Finalizer] INFO org.tahom.processor.service.callable.CallableService - Cleaning file from cache with uuid: 61286bf6-da4c-4905-b65d-d6061eb1466f
time is load for me OK because I load another web page and already lost reference for this model
17:51:10.913 [Finalizer] INFO org.tahom.processor.service.callable.CallableService - Error when cleaning file from cache with uuid: 61286bf6-da4c-4905-b65d-d6061eb1466f java.lang.NullPointerException at org.tahom.processor.service.callable.CallableService.finalizeFile(CallableService.java:65) [tahom-processor-0.2.0-SNAPSHOT.jar:?] at WICKET_org.tahom.processor.service.callable.CallableService$$FastClassByCGLIB$$82eb5c9b.invoke() [cglib-3.1.jar:?] at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [cglib-3.1.jar:?] at org.apache.wicket.proxy.LazyInitProxyFactory$AbstractCGLibInterceptor.intercept(LazyInitProxyFactory.java:350) [wicket-ioc-7.1.0.jar:7.1.0] at WICKET_org.tahom.processor.service.callable.CallableService$$EnhancerByCGLIB$$41212df1.finalizeFile() [cglib-3.1.jar:?] at org.tahom.web.model.TournamentFileReadOnlyModel.finalize(TournamentFileReadOnlyModel.java:33) [classes/:?] at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method) ~[?:1.7.0_25] at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:101) [?:1.7.0_25] at java.lang.ref.Finalizer.access$100(Finalizer.java:32) [?:1.7.0_25] at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:190) [?:1.7.0_25]
UPDATE
hm you are right. There is another intance of model. But then I dont how can be same uuid shared by different model. But this is another question
21:08:55.980 [qtp13530976-43] DEBUG org.tahom.processor.service.callable.CallableService - Creating file with uuidb485a4d1-ef67-4255-af64-4d7df6001b09 21:08:55.980 [qtp13530976-43] DEBUG org.tahom.web.model.TournamentFileReadOnlyModel - UUID b485a4d1-ef67-4255-af64-4d7df6001b09 generated for classorg.tahom.web.model.TournamentFileReadOnlyModel@1ba03be
21:08:56.794 [Finalizer] DEBUG org.tahom.web.model.TournamentFileReadOnlyModel - Class org.tahom.web.model.TournamentFileReadOnlyModel@14be425 21:08:56.907 [Finalizer] INFO org.tahom.processor.service.callable.CallableService - Cleaning file from cache with uuid: b485a4d1-ef67-4255-af64-4d7df6001b09
21:09:23.696 [Finalizer] WARN org.tahom.processor.service.callable.CallableService - Error when cleaning file from cache with uuid: b485a4d1-ef67-4255-af64-4d7df6001b09 21:09:23.696 [Finalizer] DEBUG org.tahom.web.model.TournamentFileReadOnlyModel - Class org.tahom.web.model.TournamentFileReadOnlyModel@1d76f52