/*
 * Copyright (C) 2006-2008  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cronjob.example;

import com.exedio.cope.util.JobContext;

final class InterruptableQueryJob extends AbstractJob
{
	InterruptableQueryJob()
	{
		super("InterruptableQuery", 1000, 0);
	}

	@Override
	public void run(final JobContext ctx)
	{
		System.out.println(name + ".run start");
		try
		{
			for(int i = 0; i<10; i++)
			{
				Thread.sleep(1000);
				System.out.println(name + ".run slept " + i);
				ctx.incrementProgress(result++);
				if(ctx.requestedToStop())
				{
					System.out.println(name + ".run interrupted");
					return;
				}
			}
		}
		catch(final InterruptedException e)
		{
			throw new RuntimeException(e);
		}
		System.out.println(name + ".run ready");
		ctx.incrementProgress(result++);
	}
}

@@ -1261,20 +1261,16 @@
 %0A%09%09%09%09if(
-ctx.
 requeste
@@ -1277,16 +1277,19 @@
 dToStop(
+ctx
 ))%0A%09%09%09%09%7B
@@ -1529,11 +1529,176 @@
 t++);%0A%09%7D
+%0A%0A%09@SuppressWarnings(%22deprecation%22) // OK: testing deprecated API%0A%09private static boolean requestedToStop(final JobContext ctx)%0A%09%7B%0A%09%09return ctx.requestedToStop();%0A%09%7D
 %0A%7D%0A

update copeutil: suppress warning when using deprecated JobContext#requestedToStop