@@ -1,5 +1,24 @@
/*
* Copyright 2012 Takehito Tanabe (dateofrock at gmail dot com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dateofrock.aws.simplesqs;

/**
*
* @author Takehito Tanabe (dateofrock at gmail dot com)
*/
public class SimpleSQSException extends RuntimeException {

private static final long serialVersionUID = -7171234237588238371L;
@@ -1,5 +1,24 @@
/*
* Copyright 2012 Takehito Tanabe (dateofrock at gmail dot com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dateofrock.aws.simplesqs;

/**
*
* @author Takehito Tanabe (dateofrock at gmail dot com)
*/
public enum Status {

WAITING("waiting"), IN_PROGRESS("in progress"), SUCCESS("success"), FAILURE("failure");
@@ -1,30 +1,54 @@
/*
* Copyright 2012 Takehito Tanabe (dateofrock at gmail dot com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dateofrock.aws.simplesqs;

import java.util.Random;

import com.dateofrock.simpledbmapper.SimpleDBAttribute;
import com.dateofrock.simpledbmapper.SimpleDBEntity;

@SQSJobTicket(queueName = "simple-sqs-testing")
@SimpleDBEntity(domainName = "SimpleSQS-HelloJobTicket-Testing")
/**
*
* @author Takehito Tanabe (dateofrock at gmail dot com)
*/
@SQSJobTicket(queueName = "SimpleSQS-HelloJobTicket")
@SimpleDBEntity(domainName = "SimpleSQS-HelloJobTicket", s3BucketName = "dateofrock-testing", s3KeyPrefix = "SimpleSQS-HelloJobTicket")
public class HelloJobTicket extends AbstractJobTicket {

@SimpleDBAttribute(attributeName = "userName")
public String userName;

@Override
public void prepareJob() throws Exception {
String[] users = { "Ken", "Sachiko", "John" };
public void prepare() throws Exception {
String[] presenResult = { "スベった", "ドン引きされた", "感動巨編だった" };
Random rand = new Random();
int idx = rand.nextInt(users.length);
this.userName = users[idx];
System.out.println(String.format("%s is waiting...", this.userName));
int idx = rand.nextInt(presenResult.length);
this.userName = presenResult[idx];
System.out.println(String.format("プレゼン結果を準備しました...", this.userName));
}

@Override
public void executeJob() throws Exception {
System.out.println(String.format("%s says, Hello World!!", this.userName));
public void execute() throws Exception {
System.out.println(String.format("あなたのプレゼンは、「%s」ようです。", this.userName));
Thread.sleep(1000);
}

@Override
public void processIfInProgress() {
// TODO
}

}
@@ -1,5 +1,22 @@
/*
* Copyright 2012 Takehito Tanabe (dateofrock at gmail dot com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dateofrock.aws.simplesqs;

import java.util.UUID;

import org.junit.Before;
import org.junit.Test;

@@ -16,6 +33,10 @@
import com.amazonaws.services.sqs.model.GetQueueUrlRequest;
import com.dateofrock.simpledbmapper.SimpleDBMapper;

/**
*
* @author Takehito Tanabe (dateofrock at gmail dot com)
*/
public class JobTest {
String simpleDBAPIEndPoint = "sdb.ap-northeast-1.amazonaws.com";
String sqsAPIEndPoint = "sqs.ap-northeast-1.amazonaws.com";
@@ -35,12 +56,14 @@ public void setUp() throws Exception {
}

@Test
public void test() {
public void test() throws Exception {
Reflector reflector = new Reflector();
String queueName = reflector.findQueueName(HelloJobTicket.class);
String queueUrl = this.sqs.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl();

HelloJobTicket jobTicket = new HelloJobTicket();
jobTicket.id = UUID.randomUUID().toString();

JobProducer jobProducer = new JobProducer(this.mapper, this.sqs);
jobProducer.put(jobTicket);

@@ -53,6 +76,7 @@ public void test() {
if ("0".equals(numOfMessages)) {
break;
}
Thread.sleep(1000);
}
}
}