-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
446 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...example/src/main/java/com/dangdang/example/elasticjob/spring/job/listener/FooService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.dangdang.example.elasticjob.spring.job.listener; | ||
|
||
public interface FooService { | ||
|
||
String foo(); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ple/src/main/java/com/dangdang/example/elasticjob/spring/job/listener/FooServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dangdang.example.elasticjob.spring.job.listener; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FooServiceImpl implements FooService { | ||
|
||
public String foo() { | ||
return "this is foo."; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ple/src/main/java/com/dangdang/example/elasticjob/spring/job/listener/SimpleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.dangdang.example.elasticjob.spring.job.listener; | ||
|
||
import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext; | ||
import com.dangdang.ddframe.job.api.listener.ElasticJobListener; | ||
|
||
public class SimpleListener implements ElasticJobListener { | ||
|
||
@Override | ||
public void beforeJobExecuted(final JobExecutionMultipleShardingContext shardingContext) { | ||
System.out.println("beforeJobExecuted:" + shardingContext.getJobName()); | ||
} | ||
|
||
@Override | ||
public void afterJobExecuted(final JobExecutionMultipleShardingContext shardingContext) { | ||
System.out.println("afterJobExecuted:" + shardingContext.getJobName()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...src/main/java/com/dangdang/example/elasticjob/spring/job/listener/SimpleOnceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* * | ||
* * Copyright 1999-2015 dangdang.com. | ||
* * <p> | ||
* * 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. | ||
* * </p> | ||
* | ||
* | ||
*/ | ||
|
||
package com.dangdang.example.elasticjob.spring.job.listener; | ||
|
||
import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext; | ||
import com.dangdang.ddframe.job.api.listener.AbstractDistributeOnceElasticJobListener; | ||
|
||
import javax.annotation.Resource; | ||
|
||
public class SimpleOnceListener extends AbstractDistributeOnceElasticJobListener { | ||
|
||
@Resource | ||
private FooService fooService; | ||
|
||
private final long startedTimeoutMillseconds; | ||
|
||
private final long completedTimeoutMillseconds; | ||
|
||
public SimpleOnceListener(final long startedTimeoutMillseconds, final long completedTimeoutMillseconds) { | ||
super(startedTimeoutMillseconds, completedTimeoutMillseconds); | ||
this.startedTimeoutMillseconds = startedTimeoutMillseconds; | ||
this.completedTimeoutMillseconds = completedTimeoutMillseconds; | ||
} | ||
|
||
@Override | ||
public void doBeforeJobExecutedAtLastStarted(final JobExecutionMultipleShardingContext shardingContext) { | ||
System.out.println("doBeforeJobExecutedAtLastStarted:" + fooService.foo()); | ||
} | ||
|
||
@Override | ||
public void doAfterJobExecutedAtLastCompleted(final JobExecutionMultipleShardingContext shardingContext) { | ||
System.out.println("doAfterJobExecutedAtLastCompleted:" + startedTimeoutMillseconds + "," + completedTimeoutMillseconds); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ava/com/dangdang/example/elasticjob/spring/main/SpringJobMainWthNamespaceAndListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
package com.dangdang.example.elasticjob.spring.main; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public final class SpringJobMainWthNamespaceAndListener { | ||
|
||
private SpringJobMainWthNamespaceAndListener() { | ||
} | ||
|
||
// CHECKSTYLE:OFF | ||
@SuppressWarnings("resource") | ||
public static void main(final String[] args) { | ||
// CHECKSTYLE:ON | ||
new ClassPathXmlApplicationContext("classpath:META-INF/withNamespaceAndListener.xml"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
elastic-job-example/src/main/resources/META-INF/withNamespaceAndListener.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:reg="http://www.dangdang.com/schema/ddframe/reg" | ||
xmlns:job="http://www.dangdang.com/schema/ddframe/job" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context.xsd | ||
http://www.dangdang.com/schema/ddframe/reg | ||
http://www.dangdang.com/schema/ddframe/reg/reg.xsd | ||
http://www.dangdang.com/schema/ddframe/job | ||
http://www.dangdang.com/schema/ddframe/job/job.xsd | ||
"> | ||
<context:component-scan base-package="com.dangdang.example.elasticjob" /> | ||
<context:property-placeholder location="classpath:conf/*.properties" /> | ||
|
||
<reg:zookeeper id="regCenter" serverLists="${serverLists}" namespace="${namespace}" baseSleepTimeMilliseconds="${baseSleepTimeMilliseconds}" maxSleepTimeMilliseconds="${maxSleepTimeMilliseconds}" maxRetries="${maxRetries}" nestedPort="${nestedPort}" nestedDataDir="${nestedDataDir}" /> | ||
|
||
<job:bean id="simpleElasticJob" class="com.dangdang.example.elasticjob.spring.job.SimpleJobDemo" regCenter="regCenter" shardingTotalCount="${simpleJob.shardingTotalCount}" cron="${simpleJob.cron}" shardingItemParameters="${simpleJob.shardingItemParameters}" monitorExecution="${simpleJob.monitorExecution}" monitorPort="${simpleJob.monitorPort}" failover="${simpleJob.failover}" description="${simpleJob.description}" disabled="${simpleJob.disabled}" overwrite="${simpleJob.overwrite}"> | ||
<job:listener class="com.dangdang.example.elasticjob.spring.job.listener.SimpleListener" /> | ||
<job:listener class="com.dangdang.example.elasticjob.spring.job.listener.SimpleOnceListener" startedTimeoutMillseconds="1000" completedTimeoutMillseconds="2000" /> | ||
</job:bean> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.