Copy to ClipboardCopied!Toggle word wrapToggle overflow
注記
SCR を使用すると、最も簡単に OSGi レジストリーでオブジェクトを作成および登録できます。
例
以下は、ヘルスチェックを実行して空きのディスク領域が確保されるようにする例になります。
import io.fabric8.karaf.checks.*;
import org.apache.felix.scr.annotations.*;
import org.apache.commons.io.FileSystemUtils;
import java.util.Collections;
import java.util.List;
@Component(
name = "example.DiskChecker",
immediate = true,
enabled = true,
policy = ConfigurationPolicy.IGNORE,
createPid = false
)
@Service({HealthChecker.class, ReadinessChecker.class})
public class DiskChecker implements HealthChecker, ReadinessChecker {
public List<Check> getFailingReadinessChecks() {
// lets just use the same checks for both readiness and health
return getFailingHeathChecks();
}
public List<Check> getFailingHealthChecks() {
long free = FileSystemUtils.freeSpaceKb("/");
if (free < 1024 * 500) {
return Collections.singletonList(new Check("disk-space-low", "Only " + free + "kb of disk space left."));
}
return Collections.emptyList();
}
}
import io.fabric8.karaf.checks.*;
import org.apache.felix.scr.annotations.*;
import org.apache.commons.io.FileSystemUtils;
import java.util.Collections;
import java.util.List;
@Component(
name = "example.DiskChecker",
immediate = true,
enabled = true,
policy = ConfigurationPolicy.IGNORE,
createPid = false
)
@Service({HealthChecker.class, ReadinessChecker.class})
public class DiskChecker implements HealthChecker, ReadinessChecker {
public List<Check> getFailingReadinessChecks() {
// lets just use the same checks for both readiness and health
return getFailingHeathChecks();
}
public List<Check> getFailingHealthChecks() {
long free = FileSystemUtils.freeSpaceKb("/");
if (free < 1024 * 500) {
return Collections.singletonList(new Check("disk-space-low", "Only " + free + "kb of disk space left."));
}
return Collections.emptyList();
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow