Search in sources :

Example 1 with OServerHookConfiguration

use of com.orientechnologies.orient.server.config.OServerHookConfiguration in project orientdb by orientechnologies.

the class OConfigurableHooksManager method onOpen.

public void onOpen(ODatabaseInternal iDatabase) {
    if (!iDatabase.getStorage().isRemote()) {
        final ODatabase<?> db = (ODatabase<?>) iDatabase;
        for (OServerHookConfiguration hook : configuredHooks) {
            try {
                final ORecordHook.HOOK_POSITION pos = ORecordHook.HOOK_POSITION.valueOf(hook.position);
                final ORecordHook h = (ORecordHook) Class.forName(hook.clazz).newInstance();
                if (hook.parameters != null && hook.parameters.length > 0)
                    try {
                        final Method m = h.getClass().getDeclaredMethod("config", new Class[] { OServerParameterConfiguration[].class });
                        m.invoke(h, new Object[] { hook.parameters });
                    } catch (Exception e) {
                        OLogManager.instance().warn(this, "[configure] Failed to configure hook '%s'. Parameters specified but hook don support parameters. Should have a method config with parameters OServerParameterConfiguration[] ", hook.clazz);
                    }
                db.registerHook(h, pos);
            } catch (Exception e) {
                OLogManager.instance().error(this, "[configure] Failed to configure hook '%s' due to the an error : ", e, hook.clazz, e.getMessage());
            }
        }
    }
}
Also used : OServerHookConfiguration(com.orientechnologies.orient.server.config.OServerHookConfiguration) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabase(com.orientechnologies.orient.core.db.ODatabase) Method(java.lang.reflect.Method) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook)

Example 2 with OServerHookConfiguration

use of com.orientechnologies.orient.server.config.OServerHookConfiguration in project orientdb by orientechnologies.

the class HookInstallServerTest method before.

@Before
public void before() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ClassNotFoundException, NullPointerException, IOException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
    server = new OServer();
    OServerConfigurationManager ret = new OServerConfigurationManager(this.getClass().getClassLoader().getResourceAsStream("com/orientechnologies/orient/server/network/orientdb-server-config.xml"));
    OServerHookConfiguration hc = new OServerHookConfiguration();
    hc.clazz = MyHook.class.getName();
    ret.getConfiguration().hooks = new ArrayList<OServerHookConfiguration>();
    ret.getConfiguration().hooks.add(hc);
    server.startup(ret.getConfiguration());
    server.activate();
    OServerAdmin admin = new OServerAdmin("remote:localhost");
    admin.connect("root", "D2AFD02F20640EC8B7A5140F34FCA49D2289DB1F0D0598BB9DE8AAA75A0792F3");
    admin.createDatabase("test", "nothign", "memory");
    admin.close();
}
Also used : OServerHookConfiguration(com.orientechnologies.orient.server.config.OServerHookConfiguration) OServerConfigurationManager(com.orientechnologies.orient.server.config.OServerConfigurationManager) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) Before(org.junit.Before)

Aggregations

OServerHookConfiguration (com.orientechnologies.orient.server.config.OServerHookConfiguration)2 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)1 ODatabase (com.orientechnologies.orient.core.db.ODatabase)1 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1