Skip to content

Commit

Permalink
make sure that clean of the live query data do not suppress a real ex…
Browse files Browse the repository at this point in the history
…ceptions
  • Loading branch information
tglman committed Oct 23, 2018
1 parent 5a223f8 commit 63274c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.orientechnologies.orient.core.db.ODatabaseListener;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.hook.ODocumentHookAbstract;
import com.orientechnologies.orient.core.record.impl.ODocument;

Expand All @@ -38,6 +39,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.orientechnologies.orient.core.config.OGlobalConfiguration.QUERY_LIVE_SUPPORT;

/**
* Created by luigidellaquila on 16/03/15.
*/
Expand Down Expand Up @@ -70,10 +73,10 @@ public static OLiveQueryOps getOpsReference(ODatabaseInternal db) {
}

public static Integer subscribe(Integer token, OLiveQueryListener iListener, ODatabaseInternal db) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT))) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) {
OLogManager.instance().warn(db,
"Live query support is disabled impossible to subscribe a listener, set '%s' to true for enable the live query support",
OGlobalConfiguration.QUERY_LIVE_SUPPORT.getKey());
QUERY_LIVE_SUPPORT.getKey());
return -1;
}
OLiveQueryOps ops = getOpsReference(db);
Expand All @@ -88,10 +91,10 @@ public static Integer subscribe(Integer token, OLiveQueryListener iListener, ODa
}

public static void unsubscribe(Integer id, ODatabaseInternal db) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT))) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) {
OLogManager.instance().warn(db,
"Live query support is disabled impossible to unsubscribe a listener, set '%s' to true for enable the live query support",
OGlobalConfiguration.QUERY_LIVE_SUPPORT.getKey());
QUERY_LIVE_SUPPORT.getKey());
return;
}
try {
Expand All @@ -105,7 +108,7 @@ public static void unsubscribe(Integer id, ODatabaseInternal db) {
}

public static void notifyForTxChanges(ODatabase iDatabase) {
if (Boolean.FALSE.equals(iDatabase.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (Boolean.FALSE.equals(iDatabase.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) iDatabase);
List<ORecordOperation> list;
Expand All @@ -122,16 +125,21 @@ public static void notifyForTxChanges(ODatabase iDatabase) {
}

public static void removePendingDatabaseOps(ODatabase iDatabase) {
if (Boolean.FALSE.equals(iDatabase.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (iDatabase.isClosed() || Boolean.FALSE.equals(iDatabase.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) iDatabase);
synchronized (ops.pendingOps) {
ops.pendingOps.remove(iDatabase);
try {
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) iDatabase);
synchronized (ops.pendingOps) {
ops.pendingOps.remove(iDatabase);
}
} catch (ODatabaseException ex) {
//This catch and log the exception because in some case is suppressing the real exception
OLogManager.instance().error(iDatabase, "Error cleaning the live query resources", ex);
}
}

public static void addOp(ODocument iDocument, byte iType, ODatabaseDocument database) {
if (Boolean.FALSE.equals(database.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (Boolean.FALSE.equals(database.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
ODatabaseDocument db = database;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
Expand All @@ -39,6 +40,8 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;

import static com.orientechnologies.orient.core.config.OGlobalConfiguration.QUERY_LIVE_SUPPORT;

public class OLiveQueryHookV2 {

public static class OLiveQueryOp {
Expand Down Expand Up @@ -113,10 +116,10 @@ public static OLiveQueryOps getOpsReference(ODatabaseInternal db) {
}

public static Integer subscribe(Integer token, OLiveQueryListenerV2 iListener, ODatabaseInternal db) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT))) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) {
OLogManager.instance().warn(db,
"Live query support is disabled impossible to subscribe a listener, set '%s' to true for enable the live query support",
OGlobalConfiguration.QUERY_LIVE_SUPPORT.getKey());
QUERY_LIVE_SUPPORT.getKey());
return -1;
}
OLiveQueryOps ops = getOpsReference(db);
Expand All @@ -131,10 +134,10 @@ public static Integer subscribe(Integer token, OLiveQueryListenerV2 iListener, O
}

public static void unsubscribe(Integer id, ODatabaseInternal db) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT))) {
if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) {
OLogManager.instance().warn(db,
"Live query support is disabled impossible to unsubscribe a listener, set '%s' to true for enable the live query support",
OGlobalConfiguration.QUERY_LIVE_SUPPORT.getKey());
QUERY_LIVE_SUPPORT.getKey());
return;
}
try {
Expand All @@ -148,7 +151,7 @@ public static void unsubscribe(Integer id, ODatabaseInternal db) {
}

public static void notifyForTxChanges(ODatabaseDocument database) {
if (Boolean.FALSE.equals(database.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (Boolean.FALSE.equals(database.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) database);
List<OLiveQueryOp> list;
Expand All @@ -165,16 +168,21 @@ public static void notifyForTxChanges(ODatabaseDocument database) {
}

public static void removePendingDatabaseOps(ODatabaseDocument database) {
if (Boolean.FALSE.equals(database.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (database.isClosed() || Boolean.FALSE.equals(database.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) database);
synchronized (ops.pendingOps) {
ops.pendingOps.remove(database);
try {
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) database);
synchronized (ops.pendingOps) {
ops.pendingOps.remove(database);
}
} catch (ODatabaseException ex) {
//This catch and log the exception because in some case is suppressing the real exception
OLogManager.instance().error(database, "Error cleaning the live query resources", ex);
}
}

public static void addOp(ODocument iDocument, byte iType, ODatabaseDocument database) {
if (Boolean.FALSE.equals(database.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
if (Boolean.FALSE.equals(database.getConfiguration().getValue(QUERY_LIVE_SUPPORT)))
return;
ODatabaseDocument db = database;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) db);
Expand Down

0 comments on commit 63274c3

Please sign in to comment.