rmilightbulbimpl.java

来自「Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用」· Java 代码 · 共 51 行

JAVA
51
字号
// Chapter 11, Listing 2
public class RMILightBulbImpl
	// Extends for remote object functionality
	extends java.rmi.server.UnicastRemoteObject
	// Implements a light bulb RMI interface
	implements RMILightBulb
{
	// A constructor must be provided for the remote object
	public RMILightBulbImpl() throws java.rmi.RemoteException
	{
		// Default value of off
		setBulb(false);
	}
	
	// Boolean flag to maintain light bulb state information
	private boolean lightOn;

	// Remotely accessible "on" method - turns on the light
	public void on() throws java.rmi.RemoteException
	{
		// Turn bulb on
		setBulb (true);
	}

	// Remotely accessible "off" method - turns off the light
	public void off() throws java.rmi.RemoteException
	{
		// Turn bulb off
		setBulb (false);
	}

	// Remotely accessible "isOn" method, returns state of bulb
	public boolean isOn() throws java.rmi.RemoteException
	{
		return getBulb();
	}

	// Locally accessible "setBulb" method, changes state of bulb
	public void setBulb (boolean value)
	{
		lightOn = value;
	}

	// Locally accessible "getBulb" method, returns state of bulb
	public boolean getBulb ()
	{
		return lightOn;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?