001
014
015 package com.liferay.portal.kernel.nio.intraband.welder.fifo;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import java.io.File;
021
022
025 public class FIFOUtil {
026
027 public static void createFIFO(File fifoFile) throws Exception {
028 ProcessBuilder processBuilder = new ProcessBuilder(
029 "mkfifo", fifoFile.getAbsolutePath());
030
031 Process mkfifoProcess = null;
032
033 try {
034 mkfifoProcess = processBuilder.start();
035
036 int result = mkfifoProcess.waitFor();
037
038 if (result != 0) {
039 throw new Exception(
040 "Unable to create FIFO with command \"mkfifo\", " +
041 "external process returned " + result);
042 }
043 }
044 finally {
045 if (mkfifoProcess != null) {
046 mkfifoProcess.destroy();
047 }
048 }
049 }
050
051 public static boolean isFIFOSupported() {
052 return _fifoSupported;
053 }
054
055 private static Log _log = LogFactoryUtil.getLog(FIFOUtil.class);
056
057 private static boolean _fifoSupported;
058
059 static {
060 try {
061 File tempFIFOFile = new File(
062 System.getProperty("java.io.tmpdir"),
063 "temp-fifo-" + System.currentTimeMillis());
064
065 try {
066 createFIFO(tempFIFOFile);
067 }
068 finally {
069 if (!tempFIFOFile.delete()) {
070 if (tempFIFOFile.exists()) {
071 tempFIFOFile.deleteOnExit();
072 }
073 }
074 }
075
076 _fifoSupported = true;
077 }
078 catch (Throwable t) {
079 if (_log.isWarnEnabled()) {
080 _log.warn("Unable to detect FIFO support", t);
081 }
082
083 _fifoSupported = false;
084 }
085 }
086
087 }