use of org.apache.ignite.console.demo.model.Car in project ignite by apache.
the class DemoCachesLoadService method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(ServiceContext ctx) throws Exception {
cachePool.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
IgniteCache<Integer, Employee> cacheEmployee = ignite.cache(EMPLOYEE_CACHE_NAME);
if (cacheEmployee != null)
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
for (int i = 0, n = 1; i < cnt; i++, n++) {
Integer id = rnd.nextInt(EMPL_CNT);
Integer depId = rnd.nextInt(DEP_CNT);
double r = rnd.nextDouble();
cacheEmployee.put(id, new Employee(id, depId, depId, "First name employee #" + n, "Last name employee #" + n, "Email employee #" + n, "Phone number employee #" + n, new java.sql.Date((long) (r * range)), "Job employee #" + n, 500 + AgentDemoUtils.round(r * 2000, 2)));
if (rnd.nextBoolean())
cacheEmployee.remove(rnd.nextInt(EMPL_CNT));
cacheEmployee.get(rnd.nextInt(EMPL_CNT));
}
if (rnd.nextInt(100) > 20)
tx.commit();
}
} catch (Throwable e) {
if (!e.getMessage().contains("cache is stopped"))
ignite.log().error("Cache write task execution error", e);
}
}
}, 10, 3, TimeUnit.SECONDS);
cachePool.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
IgniteCache<Integer, Car> cache = ignite.cache(CAR_CACHE_NAME);
if (cache != null)
for (int i = 0; i < cnt; i++) {
Integer carId = rnd.nextInt(CAR_CNT);
cache.put(carId, new Car(carId, rnd.nextInt(PARK_CNT), "Car #" + (i + 1)));
if (rnd.nextBoolean())
cache.remove(rnd.nextInt(CAR_CNT));
}
} catch (IllegalStateException ignored) {
// No-op.
} catch (Throwable e) {
if (!e.getMessage().contains("cache is stopped"))
ignite.log().error("Cache write task execution error", e);
}
}
}, 10, 3, TimeUnit.SECONDS);
}
use of org.apache.ignite.console.demo.model.Car in project ignite by apache.
the class DemoCachesLoadService method cacheCar.
/**
* Configure cacheEmployee.
*/
private static CacheConfiguration cacheCar() {
CacheConfiguration ccfg = cacheConfiguration(CAR_CACHE_NAME);
// Configure cacheCar types.
Collection<QueryEntity> qryEntities = new ArrayList<>();
// CAR.
QueryEntity type = new QueryEntity();
qryEntities.add(type);
type.setKeyType(Integer.class.getName());
type.setValueType(Car.class.getName());
// Query fields for CAR.
LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();
qryFlds.put("id", "java.lang.Integer");
qryFlds.put("parkingId", "java.lang.Integer");
qryFlds.put("name", "java.lang.String");
type.setFields(qryFlds);
ccfg.setQueryEntities(qryEntities);
return ccfg;
}
Aggregations