@Override public Object perform(InvocationContext ctx) throws Throwable { // It's not worth looking up the entry if we're never going to apply the change. if (valueMatcher == ValueMatcher.MATCH_NEVER) { successful = false; return null; } MVCCEntry e = (MVCCEntry) ctx.lookupEntry(key); if (e == null || e.isNull() || e.isRemoved()) { nonExistent = true; if (valueMatcher.matches(e, value, null, valueEquivalence)) { if (e != null) { e.setChanged(true); e.setRemoved(true); } return isConditional() ? true : null; } else { log.trace("Nothing to remove since the entry doesn't exist in the context or it is null"); successful = false; return false; } } if (!valueMatcher.matches(e, value, null, valueEquivalence)) { successful = false; return false; } if (this instanceof EvictCommand) { e.setEvicted(true); } return performRemove(e, ctx); }
private ValueMatcher getValueMatcher(Object o) { SerializeFunctionWith ann = o.getClass().getAnnotation(SerializeFunctionWith.class); if (ann != null) return ValueMatcher.valueOf(ann.valueMatcher().toString()); Externalizer ext = externalizerTable.getExternalizer(o); if (ext != null && ext instanceof LambdaExternalizer) return ValueMatcher.valueOf(((LambdaExternalizer) ext).valueMatcher(o).toString()); return ValueMatcher.MATCH_ALWAYS; }
private boolean checkProperties( AbstractPatternObject<? extends PropertyContainer> patternObject, PropertyContainer object) { PropertyContainer associatedObject = patternObject.getAssociation(); if (associatedObject != null && !object.equals(associatedObject)) { return false; } for (Map.Entry<String, Collection<ValueMatcher>> matchers : patternObject.getPropertyConstraints()) { String key = matchers.getKey(); Object propertyValue = object.getProperty(key, null); for (ValueMatcher matcher : matchers.getValue()) { if (!matcher.matches(propertyValue)) { return false; } } } return true; }
/** * It returns the next matching moment as a millis value. * * @return The next matching moment as a millis value. */ public synchronized long nextMatchingTime() { // Go a minute ahead. time += 60000; // Is it matching? if (schedulingPattern.match(time)) { return time; } // Go through the matcher groups. int size = schedulingPattern.matcherSize; long[] times = new long[size]; for (int k = 0; k < size; k++) { // Ok, split the time! Calendar c = new GregorianCalendar(); c.setTimeInMillis(time); int minute = c.get(Calendar.MINUTE); int hour = c.get(Calendar.HOUR_OF_DAY); int dayOfMonth = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); // Gets the matchers. ValueMatcher minuteMatcher = (ValueMatcher) schedulingPattern.minuteMatchers.get(k); ValueMatcher hourMatcher = (ValueMatcher) schedulingPattern.hourMatchers.get(k); ValueMatcher dayOfMonthMatcher = (ValueMatcher) schedulingPattern.dayOfMonthMatchers.get(k); ValueMatcher dayOfWeekMatcher = (ValueMatcher) schedulingPattern.dayOfWeekMatchers.get(k); ValueMatcher monthMatcher = (ValueMatcher) schedulingPattern.monthMatchers.get(k); for (; ; ) { // day of week for (; ; ) { // month for (; ; ) { // day of month for (; ; ) { // hour for (; ; ) { // minutes if (minuteMatcher.match(minute)) { break; } else { minute++; if (minute > 59) { minute = 0; hour++; } } } if (hour > 23) { hour = 0; dayOfMonth++; } if (hourMatcher.match(hour)) { break; } else { hour++; minute = 0; } } if (dayOfMonth > 31) { dayOfMonth = 1; month++; } if (dayOfMonthMatcher.match(dayOfMonth)) { break; } else { dayOfMonth++; hour = 0; minute = 0; } } if (month > Calendar.DECEMBER) { month = Calendar.JANUARY; year++; } if (monthMatcher.match(month + 1)) { break; } else { month++; dayOfMonth = 1; hour = 0; minute = 0; } } // Is this ok? c = new GregorianCalendar(); c.set(Calendar.MINUTE, minute); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); c.set(Calendar.MONTH, month); c.set(Calendar.YEAR, year); // Day-of-month/month/year compatibility check. int oldDayOfMonth = dayOfMonth; int oldMonth = month; int oldYear = year; dayOfMonth = c.get(Calendar.DAY_OF_MONTH); month = c.get(Calendar.MONTH); year = c.get(Calendar.YEAR); if (month != oldMonth || dayOfMonth != oldDayOfMonth || year != oldYear) { // Take another spin! continue; } // Day of week. int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); if (dayOfWeekMatcher.match(dayOfWeek - 1)) { break; } else { dayOfMonth++; hour = 0; minute = 0; if (dayOfMonth > 31) { dayOfMonth = 1; month++; if (month > Calendar.DECEMBER) { month = Calendar.JANUARY; year++; } } } } // Seems it matches! times[k] = (c.getTimeInMillis() / (1000 * 60)) * 1000 * 60; } // Which one? long min = Long.MAX_VALUE; for (int k = 0; k < size; k++) { if (times[k] < min) { min = times[k]; } } // Updates the object current time value. time = min; // Here it is. return time; }