Skip to content

Commit c6da848

Browse files
authored
Merge pull request #7 from vinscom/add-mongo-scheduler
Added Mongo and Scheduler
2 parents edd8544 + 0fb3953 commit c6da848

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#/io/vertx/ext/mongo/MongoClientInstance
2+
$class=io.vertx.reactivex.ext.mongo.MongoClientInstance
3+
4+
vertx^=/io/vertx/core/VertxInstance.vertx
5+
config=mongoConfig.json
6+
enable=false

config-layers/common/io/vertx/ext/mongo/mongoConfig.json

Whitespace-only changes.

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<artifactId>vertx-auth-oauth2</artifactId>
6666
<version>3.5.0</version>
6767
</dependency>
68+
<dependency>
69+
<groupId>io.vertx</groupId>
70+
<artifactId>vertx-mongo-client</artifactId>
71+
<version>3.5.0</version>
72+
</dependency>
6873
</dependencies>
6974
<properties>
7075
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package in.erail.schedular;
2+
3+
import in.erail.glue.annotation.StartService;
4+
import io.reactivex.Observable;
5+
import io.reactivex.Scheduler;
6+
import io.reactivex.schedulers.Schedulers;
7+
import java.util.concurrent.TimeUnit;
8+
9+
/**
10+
*
11+
* @author vinay
12+
*/
13+
public abstract class SchedulerService {
14+
15+
private SchedulerType mSchedularType;
16+
private TimeUnit mTimeUnit;
17+
private long mInterval;
18+
private boolean mRecurring;
19+
20+
@StartService
21+
void start() {
22+
23+
Scheduler scheduler;
24+
25+
switch (mSchedularType) {
26+
case COMPUTATION:
27+
scheduler = Schedulers.computation();
28+
break;
29+
case IO:
30+
scheduler = Schedulers.io();
31+
break;
32+
case NEWTHREAD:
33+
scheduler = Schedulers.newThread();
34+
break;
35+
case SINGLE:
36+
scheduler = Schedulers.single();
37+
break;
38+
default:
39+
scheduler = Schedulers.io();
40+
}
41+
42+
if (isRecurring()) {
43+
Observable
44+
.interval(getInterval(), getTimeUnit(), scheduler)
45+
.subscribe(this::performScheduledTask);
46+
} else {
47+
Observable
48+
.timer(getInterval(), getTimeUnit(), scheduler)
49+
.subscribe(this::performScheduledTask);
50+
}
51+
}
52+
53+
public void performScheduledTask(Long pId) {
54+
}
55+
56+
public SchedulerType getSchedularType() {
57+
return mSchedularType;
58+
}
59+
60+
public void setSchedularType(SchedulerType pSchedularType) {
61+
this.mSchedularType = pSchedularType;
62+
}
63+
64+
public TimeUnit getTimeUnit() {
65+
return mTimeUnit;
66+
}
67+
68+
public void setTimeUnit(TimeUnit pTimeUnit) {
69+
this.mTimeUnit = pTimeUnit;
70+
}
71+
72+
public long getInterval() {
73+
return mInterval;
74+
}
75+
76+
public void setInterval(long pInterval) {
77+
this.mInterval = pInterval;
78+
}
79+
80+
public boolean isRecurring() {
81+
return mRecurring;
82+
}
83+
84+
public void setRecurring(boolean pRecurring) {
85+
this.mRecurring = pRecurring;
86+
}
87+
88+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package in.erail.schedular;
2+
3+
/**
4+
*
5+
* @author vinay
6+
*/
7+
public enum SchedulerType {
8+
COMPUTATION,
9+
IO,
10+
NEWTHREAD,
11+
SINGLE;
12+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.vertx.reactivex.ext.mongo;
2+
3+
import in.erail.glue.annotation.StartService;
4+
import io.vertx.core.json.JsonObject;
5+
import io.vertx.reactivex.core.Vertx;
6+
7+
/**
8+
*
9+
* @author vinay
10+
*/
11+
public class MongoClientInstance {
12+
13+
private MongoClient mMongoClient;
14+
private Vertx mVertx;
15+
private JsonObject mConfig;
16+
private boolean mEnable;
17+
18+
@StartService
19+
public void start() {
20+
if (isEnable()) {
21+
mMongoClient = MongoClient.createShared(getVertx(), getConfig());
22+
}
23+
}
24+
25+
public MongoClient getMongoClient() {
26+
return mMongoClient;
27+
}
28+
29+
public void setMongoClient(MongoClient pMongoClient) {
30+
this.mMongoClient = pMongoClient;
31+
}
32+
33+
public Vertx getVertx() {
34+
return mVertx;
35+
}
36+
37+
public void setVertx(Vertx pVertx) {
38+
this.mVertx = pVertx;
39+
}
40+
41+
public JsonObject getConfig() {
42+
return mConfig;
43+
}
44+
45+
public void setConfig(JsonObject pConfig) {
46+
this.mConfig = pConfig;
47+
}
48+
49+
public boolean isEnable() {
50+
return mEnable;
51+
}
52+
53+
public void setEnable(boolean pEnable) {
54+
this.mEnable = pEnable;
55+
}
56+
57+
}

0 commit comments

Comments
 (0)