All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fusesource.leveldbjni.internal.NativeLogger Maven / Gradle / Ivy

Go to download

An uber jar which contains all the leveldbjni platform libraries and dependencies

The newest version!
/*
 * Copyright (C) 2011, FuseSource Corp.  All rights reserved.
 *
 *     http://fusesource.com
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 *    * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *    * Neither the name of FuseSource Corp. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.fusesource.leveldbjni.internal;

import org.fusesource.hawtjni.runtime.JniArg;
import org.fusesource.hawtjni.runtime.JniClass;
import org.fusesource.hawtjni.runtime.JniField;
import org.fusesource.hawtjni.runtime.JniMethod;

import static org.fusesource.hawtjni.runtime.ArgFlag.CRITICAL;
import static org.fusesource.hawtjni.runtime.ArgFlag.NO_OUT;
import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
import static org.fusesource.hawtjni.runtime.FieldFlag.POINTER_FIELD;
import static org.fusesource.hawtjni.runtime.MethodFlag.*;

/**
 * 

* Provides a java interface to the C++ leveldb::Logger class. *

* * @author Hiram Chirino */ public abstract class NativeLogger extends NativeObject { @JniClass(name="JNILogger", flags={STRUCT, CPP}) static public class LoggerJNI { static { NativeDB.LIBRARY.load(); init(); } @JniMethod(flags={CPP_NEW}) public static final native long create(); @JniMethod(flags={CPP_DELETE}) public static final native void delete( long self ); public static final native void memmove ( @JniArg(cast="void *") long dest, @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) LoggerJNI src, @JniArg(cast="size_t") long size); @JniField(cast="jobject", flags={POINTER_FIELD}) long target; @JniField(cast="jmethodID", flags={POINTER_FIELD}) long log_method; @JniMethod(flags={CONSTANT_INITIALIZER}) private static final native void init(); @JniField(flags={CONSTANT}, accessor="sizeof(struct JNILogger)") static int SIZEOF; } private long globalRef; public NativeLogger() { super(LoggerJNI.create()); try { globalRef = NativeDB.DBJNI.NewGlobalRef(this); if( globalRef==0 ) { throw new RuntimeException("jni call failed: NewGlobalRef"); } LoggerJNI struct = new LoggerJNI(); struct.log_method = NativeDB.DBJNI.GetMethodID(this.getClass(), "log", "(Ljava/lang/String;)V"); if( struct.log_method ==0 ) { throw new RuntimeException("jni call failed: GetMethodID"); } struct.target = globalRef; LoggerJNI.memmove(self, struct, LoggerJNI.SIZEOF); } catch (RuntimeException e) { delete(); throw e; } } NativeLogger(long ptr) { super(ptr); } public void delete() { if( globalRef!=0 ) { NativeDB.DBJNI.DeleteGlobalRef(globalRef); globalRef = 0; } } public abstract void log(String message); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy