Hello!
  I've followed the suggestion of adding a shutdown hook inside the Bolt as
it was suggested by this post
http://grokbase.com/t/gg/storm-user/136ks2tgmn/how-do-you-perform-cleanup-when-killing-a-topology
(see
Derek's).
The hook is initialized, but the run method is not called when the topology
is killed.

Please advice.
Thanks.
 Florin


Find bellow a shortened version of the code :

public void prepare() {
  CleanupShutdownHook hook = new CleanupShutdownHook();
hook.attachShutDownHook();
  csvWriter = new CSVWriter(new BufferedWriter(new FileWriter("myFile")));
}

public void cleanup() {
 csvWriter.close()
}
}

public class CleanupShutdownHook {
public void attachShutDownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
 cleanup();
}
});
  }
}



On Mon, Aug 18, 2014 at 3:12 PM, Spico Florin <[email protected]> wrote:

> Hello!
>    I'm using the storm version 0.9.2 incubating. I have a CSV file is
> initialized in the prepare  method
> of a BaseBasicBolt
>  prepare() {
>    csvWriter = new CSVWriter(new BufferedWriter(new FileWriter("myFile")));
>  }
> and I would like to close it when I kill the topology
>
> public void cleanup() {
>    csvWriter.close()
> }
>
> I have observed that when I was shutting down the Local cluster by calling
> the LocalCluster shutdown method, the cleanup method was called. But, when
> I kill the topology the cleanup method is not called anymore.
>   Can you please advice on how to properly close the resources when
> killing the topology?
>
> I look forward for your answers.
>   Regards,
>  Florin
>
>
>
>

Reply via email to