Java Code Examples for java.lang.reflect.Field.getLong()

The following are Jave code examples for showing how to use getLong() of the java.lang.reflect.Field class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: Unsafe.java   View Source Code Vote up 6 votes
public long getLongVolatile(Object obj, long offset)
{
    if (obj instanceof cli.System.Array)
    {
        synchronized(this)
        {
            return ReadInt64(obj, offset);
        }
    }
    else
    {
        Field field = getField(offset);
        synchronized(field)
        {
            try
            {
                return field.getLong(obj);
            }
            catch(IllegalAccessException x)
            {
                throw (InternalError)new InternalError().initCause(x);
            }
        }
    }
}
 
Example 2
Project: nifi-registry   File: OSUtils.java   View Source Code Vote up 6 votes
/**
 * @param process NiFi Registry Process Reference
 * @param logger  Logger Reference for Debug
 * @return        Returns pid or null in-case pid could not be determined
 * This method takes {@link Process} and {@link Logger} and returns
 * the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
 * In-case it fails to determine the pid, it will return Null.
 * Purpose for the Logger is to log any interaction for debugging.
 */
private static Long getWindowsProcessId(final Process process, final Logger logger) {
    /* determine the pid on windows plattforms */
    try {
        Field f = process.getClass().getDeclaredField("handle");
        f.setAccessible(true);
        long handl = f.getLong(process);

        Kernel32 kernel = Kernel32.INSTANCE;
        WinNT.HANDLE handle = new WinNT.HANDLE();
        handle.setPointer(Pointer.createConstant(handl));
        int ret = kernel.GetProcessId(handle);
        logger.debug("Detected pid: {}", ret);
        return Long.valueOf(ret);
    } catch (final IllegalAccessException | NoSuchFieldException nsfe) {
        logger.debug("Could not find PID for child process due to {}", nsfe);
    }
    return null;
}
 
Example 3
Project: openjdk-jdk10   File: GatherProcessInfoTimeoutHandler.java   View Source Code Vote up 6 votes
@Override
protected long getProcessId(Process process) {
    long result = super.getProcessId(process);
    if (result == 0L) {
        /* jtreg didn't find pid, most probably we are on JDK < 9
           there is no Process::getPid */
        if (HAS_NATIVE_LIBRARY && "windows".equals(OS.current().family)) {
            try {
                Field field = process.getClass().getDeclaredField("handle");
                boolean old = field.isAccessible();
                try {
                    field.setAccessible(true);
                    long handle = field.getLong(process);
                    result = getWin32Pid(handle);
                } finally {
                    field.setAccessible(old);
                }
            } catch (ReflectiveOperationException e) {
                e.printStackTrace(log);
            }
        }
    }
    return result;
}
 
Example 4
Project: EatDubbo   File: JavaSerializer.java   View Source Code Vote up 5 votes
void serialize(AbstractHessianOutput out, Object obj, Field field)
     throws IOException
   {
     long value = 0;

     try {
value = field.getLong(obj);
     } catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
     }

     out.writeLong(value);
   }
 
Example 5
Project: LKDBHelper-ORM-Android   File: LKDBTableUtils.java   View Source Code Vote up 5 votes
public static <T extends ILKDBModel> long getRowid(T mode){
    LKModelInfos infos =  getModelInfos(mode.getClass());
    String rowidName = infos.getDb_rowidAliasName();
    if(TextUtils.isEmpty(rowidName)){
        return 0;
    }
    Field field = infos.getFieldMaps().get(rowidName);
    long rowid = 0;
    try {
        rowid = field.getLong(mode);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return rowid;
}
 
Example 6
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ProducerManagerTest.java   View Source Code Vote up 5 votes
@Test
public void scanNotActiveChannel() throws Exception {
    producerManager.registerProducer(group, clientInfo);
    assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();

    Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT");
    field.setAccessible(true);
    long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager);
    clientInfo.setLastUpdateTimestamp(System.currentTimeMillis() - CHANNEL_EXPIRED_TIMEOUT - 10);
    when(channel.close()).thenReturn(mock(ChannelFuture.class));
    producerManager.scanNotActiveChannel();
    assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();
}
 
Example 7
Project: easyfilemanager   File: StorageUtils.java   View Source Code Vote up 5 votes
private long getLong(Object object, String id) {
    long value = 0l;
    try {
        Field field = object.getClass().getDeclaredField(id);
        field.setAccessible(true);
        value = field.getLong(object);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}
 
Example 8
Project: dubbocloud   File: JavaSerializer.java   View Source Code Vote up 5 votes
void serialize(AbstractHessianOutput out, Object obj, Field field)
     throws IOException
   {
     long value = 0;

     try {
value = field.getLong(obj);
     } catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
     }

     out.writeLong(value);
   }
 
Example 9
Project: JavaFX-FrameRateMeter   File: OldFXCanvas.java   View Source Code Vote up 5 votes
private static void initFx() {
    AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
        System.setProperty("javafx.embed.isEventThread", "true");
        System.setProperty("glass.win.uiScale", "100%");
        System.setProperty("glass.win.renderScale", "100%");
        return null;
    });
    Map map = Application.getDeviceDetails();
    if (map == null) {
        Application.setDeviceDetails(map = new HashMap());
    }
    if (map.get("javafx.embed.eventProc") == null) {
        long eventProc = 0;
        try {
            Field field = Display.class.getDeclaredField("eventProc");
            field.setAccessible(true);
            if (field.getType() == int.class) {
                eventProc = field.getLong(Display.getDefault());
            } else {
                if (field.getType() == long.class) {
                    eventProc = field.getLong(Display.getDefault());
                }
            }
        } catch (Throwable th) {
            //Fail silently
        }
        map.put("javafx.embed.eventProc", eventProc);
    }
    // Note that calling PlatformImpl.startup more than once is OK
    PlatformImpl.startup(() -> {
        Application.GetApplication().setName(Display.getAppName());
    });
}
 
Example 10
Project: FastTextView   File: FpsCalculator.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void start() {
	Log.d(TAG, "start vsync detect");
	if (mRunning) {
		return;
	}
	
	mRunning = true;

	syncCheckThread = new Thread(new Runnable() {
		@Override
		public void run() {
			for (;;) {
				if (!mRunning) {
					break;
				}
				syncCheckThread();
			}
		}
	});
	syncCheckThread.start();
	
	Choreographer chor = Choreographer.getInstance();
	Field field;
	try {
		field = chor.getClass().getDeclaredField("mFrameIntervalNanos");
		field.setAccessible(true);
		mFrameIntervalNanos = field.getLong(chor);
		Log.d(TAG, "mFrameIntervalNanos " + mFrameIntervalNanos);
	} catch (Exception e) {
		Log.e(TAG, "error: " + e.getMessage());
	}
	chor.postFrameCallback(frameCallback);

}
 
Example 11
Project: jsf-sdk   File: JavaSerializer.java   View Source Code Vote up 5 votes
void serialize(AbstractHessianOutput out, Object obj, Field field)
     throws IOException
   {
     long value = 0;

     try {
value = field.getLong(obj);
     } catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
     }

     out.writeLong(value);
   }
 
Example 12
Project: FireFiles   File: StorageUtils.java   View Source Code Vote up 5 votes
private long getLong(Object object, String id) {
    long value = 0l;
    try {
        Field field = object.getClass().getDeclaredField(id);
        field.setAccessible(true);
        value = field.getLong(object);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}
 
Example 13
Project: dubbox-hystrix   File: JavaSerializer.java   View Source Code Vote up 5 votes
void serialize(AbstractHessianOutput out, Object obj, Field field)
     throws IOException
   {
     long value = 0;

     try {
value = field.getLong(obj);
     } catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
     }

     out.writeLong(value);
   }
 
Example 14
Project: simple-share-android   File: StorageUtils.java   View Source Code Vote up 5 votes
private long getLong(Object object, String id) {
    long value = 0l;
    try {
        Field field = object.getClass().getDeclaredField(id);
        field.setAccessible(true);
        value = field.getLong(object);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}
 
Example 15
Project: rmq4note   File: ProducerManagerTest.java   View Source Code Vote up 5 votes
@Test
public void scanNotActiveChannel() throws Exception {
    producerManager.registerProducer(group, clientInfo);
    assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();

    Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT");
    field.setAccessible(true);
    long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager);
    clientInfo.setLastUpdateTimestamp(System.currentTimeMillis() - CHANNEL_EXPIRED_TIMEOUT - 10);
    when(channel.close()).thenReturn(mock(ChannelFuture.class));
    producerManager.scanNotActiveChannel();
    assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();
}
 
Example 16
Project: openjdk-jdk10   File: EmbeddedFrameGrabTest.java   View Source Code Vote up 5 votes
/**
 * Test fails if it throws any exception.
 *
 * @throws Exception
 */
private void init() throws Exception {

    if (!System.getProperty("os.name").startsWith("Windows")) {
        System.out.println("This is Windows only test.");
        return;
    }

    final Frame frame = new Frame("AWT Frame");
    frame.pack();
    frame.setSize(200, 200);
    FramePeer frame_peer = AWTAccessor.getComponentAccessor()
                                .getPeer(frame);
    Class comp_peer_class
            = Class.forName("sun.awt.windows.WComponentPeer");
    Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
    hwnd_field.setAccessible(true);
    long hwnd = hwnd_field.getLong(frame_peer);

    Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
    Constructor constructor
            = clazz.getConstructor(new Class[]{long.class});
    final Frame embedded_frame
            = (Frame) constructor.newInstance(new Object[]{
                new Long(hwnd)});;
    final JComboBox<String> combo = new JComboBox<>(new String[]{
        "Item 1", "Item 2"
    });
    combo.setSelectedIndex(1);
    final Panel p = new Panel();
    p.setLayout(new BorderLayout());
    embedded_frame.add(p, BorderLayout.CENTER);
    embedded_frame.validate();
    p.add(combo);
    p.validate();
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.delay(2000);
    Rectangle clos = new Rectangle(
            combo.getLocationOnScreen(), combo.getSize());
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!combo.isPopupVisible()) {
        throw new RuntimeException("Combobox popup is not visible!");
    }
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (combo.getSelectedIndex() != 0) {
        throw new RuntimeException("Combobox selection has not changed!");
    }
    embedded_frame.remove(p);
    embedded_frame.dispose();
    frame.dispose();

}
 
Example 17
Project: angel   File: MLRPC.java   View Source Code Vote up 4 votes
static long getProtocolVersion(Class<? extends VersionedProtocol> protocol)
    throws NoSuchFieldException, IllegalAccessException {
  Field versionField = protocol.getField("VERSION");
  versionField.setAccessible(true);
  return versionField.getLong(protocol);
}
 
Example 18
Project: incubator-netbeans   File: LocalNativeProcess.java   View Source Code Vote up 4 votes
private void createWin() throws IOException, InterruptedException {
    // Don't use shell wrapping on Windows...
    // Mostly this is because exec works not as expected and we cannot
    // control processes started with exec method....

    // Suspend is not supported on Windows.

    final ProcessBuilder pb = new ProcessBuilder(); // NOI18N

    final MacroMap jointEnv = MacroMap.forExecEnv(ExecutionEnvironmentFactory.getLocal());
    jointEnv.putAll(info.getEnvironment());

    if (isInterrupted()) {
        throw new InterruptedException();
    }

    if (info.isUnbuffer()) {
        UnbufferSupport.initUnbuffer(info.getExecutionEnvironment(), jointEnv);
    }

    pb.environment().clear();

    for (Entry<String, String> envEntry : jointEnv.entrySet()) {
        pb.environment().put(envEntry.getKey(), envEntry.getValue());
    }

    pb.redirectErrorStream(info.isRedirectError());
    pb.command(info.getCommand());

    if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest(String.format("Command: %s", info.getCommand())); // NOI18N
    }

    String wdir = info.getWorkingDirectory(true);
    if (wdir != null) {
        File wd = new File(wdir);
        if (!wd.exists()) {
            throw new FileNotFoundException(loc("NativeProcess.noSuchDirectoryError.text", wd.getAbsolutePath())); // NOI18N
        }
        pb.directory(wd);
        if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest(String.format("Working directory: %s", wdir)); // NOI18N
        }
    }

    process = pb.start();

    creation_ts = System.nanoTime();

    errorPipedOutputStream = new PipedOutputStream();
    errorPipedInputStream = new PipedInputStream(errorPipedOutputStream);

    setErrorStream(new SequenceInputStream(process.getErrorStream(), errorPipedInputStream));
    setInputStream(process.getInputStream());
    setOutputStream(process.getOutputStream());

    int newPid = 12345;

    try {
        String className = process.getClass().getName();
        if ("java.lang.Win32Process".equals(className) || "java.lang.ProcessImpl".equals(className)) { // NOI18N
            Field f = process.getClass().getDeclaredField("handle"); // NOI18N
            f.setAccessible(true);
            long phandle = f.getLong(process);

            Win32APISupport kernel = Win32APISupport.instance;
            Win32APISupport.HANDLE handle = new Win32APISupport.HANDLE();
            handle.setPointer(Pointer.createConstant(phandle));
            newPid = kernel.GetProcessId(handle);
        }
    } catch (Throwable e) {
    }

    ByteArrayInputStream bis = new ByteArrayInputStream(("" + newPid).getBytes()); // NOI18N

    readPID(bis);
}
 
Example 19
Project: ETF-Java   File: ReflectionUtils.java   View Source Code Vote up 4 votes
public static Object getField(Object instance, Field field) throws IllegalAccessException {
	if (UNSAFE != null) {
		if (int.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (long.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (double.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (void.class.equals(field.getType())) {
			return null;
		} else if (float.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (byte.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (char.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (boolean.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (short.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else {
			return ((sun.misc.Unsafe) UNSAFE).getObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		}
	} else { //Fallback if unsafe isn't available
		field.setAccessible(true);
		if (int.class.equals(field.getType())) {
			return field.getInt(instance);
		} else if (long.class.equals(field.getType())) {
			return field.getLong(instance);
		} else if (double.class.equals(field.getType())) {
			return field.getDouble(instance);
		} else if (void.class.equals(field.getType())) {
			return null;
		} else if (float.class.equals(field.getType())) {
			return field.getFloat(instance);
		} else if (byte.class.equals(field.getType())) {
			return field.getByte(instance);
		} else if (char.class.equals(field.getType())) {
			return field.getChar(instance);
		} else if (boolean.class.equals(field.getType())) {
			return field.getBoolean(instance);
		} else if (short.class.equals(field.getType())) {
			return field.getShort(instance);
		} else {
			return field.get(instance);
		}
	}
}
 
Example 20
Project: LightSIP   File: SIPObject.java   View Source Code Vote up 4 votes
/**
 * An introspection based equality predicate for SIPObjects.
 *@param other the other object to test against.
 */
public boolean equals(Object other) {
    if (!this.getClass().equals(other.getClass()))
        return false;
    SIPObject that = (SIPObject) other;
    Class myclass = this.getClass();
    Class hisclass = other.getClass();
    while (true) {
        Field[] fields = myclass.getDeclaredFields();
        if (!hisclass.equals(myclass))
            return false;
        Field[] hisfields = hisclass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];
            Field g = hisfields[i];
            // Only print protected and public members.
            int modifier = f.getModifiers();
            if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE)
                continue;
            Class fieldType = f.getType();
            String fieldName = f.getName();
            if (fieldName.compareTo("stringRepresentation") == 0) {
                continue;
            }
            if (fieldName.compareTo("indentation") == 0) {
                continue;
            }
            try {
                // Primitive fields are printed with type: value
                if (fieldType.isPrimitive()) {
                    String fname = fieldType.toString();
                    if (fname.compareTo("int") == 0) {
                        if (f.getInt(this) != g.getInt(that))
                            return false;
                    } else if (fname.compareTo("short") == 0) {
                        if (f.getShort(this) != g.getShort(that))
                            return false;
                    } else if (fname.compareTo("char") == 0) {
                        if (f.getChar(this) != g.getChar(that))
                            return false;
                    } else if (fname.compareTo("long") == 0) {
                        if (f.getLong(this) != g.getLong(that))
                            return false;
                    } else if (fname.compareTo("boolean") == 0) {
                        if (f.getBoolean(this) != g.getBoolean(that))
                            return false;
                    } else if (fname.compareTo("double") == 0) {
                        if (f.getDouble(this) != g.getDouble(that))
                            return false;
                    } else if (fname.compareTo("float") == 0) {
                        if (f.getFloat(this) != g.getFloat(that))
                            return false;
                    }
                } else if (g.get(that) == f.get(this))
                    continue;
                else if (f.get(this) == null && g.get(that) != null)
                    return false;
                else if (g.get(that) == null && f.get(this) != null)
                    return false;
                else if (!f.get(this).equals(g.get(that)))
                    return false;
            } catch (IllegalAccessException ex1) {
                System.out.println("accessed field " + fieldName);
                System.out.println("modifier  " + modifier);
                System.out.println("modifier.private  " + Modifier.PRIVATE);
                InternalErrorHandler.handleException(ex1);
            }
        }
        if (myclass.equals(SIPObject.class))
            break;
        else {
            myclass = myclass.getSuperclass();
            hisclass = hisclass.getSuperclass();
        }
    }
    return true;
}