package me.haosdent.cgroup.subsystem;

import me.haosdent.cgroup.manage.Group;
import me.haosdent.cgroup.util.Constants;
import me.haosdent.cgroup.util.Shell;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public abstract class Common {

  protected Shell shell;
  protected Group group;

  public static final int SUBSYS = Constants.SUBSYS_COMMON;
  public List<Integer> taskList = new LinkedList<Integer>();

  public Common(Group group) {
    this.group = group;
    this.shell = group.getShell();
    List<Common> subSystemList = group.getSubSystemList();
    synchronized (subSystemList) {
      subSystemList.add(this);
    }
  }

  public Group getGroup() {
    return group;
  }

  public Shell getShell() {
    return shell;
  }

  public void addTask(int task) throws IOException {
    shell.cgclassify(group.getName(), SUBSYS, task);
    taskList.add(task);
  }

  public void setEventControl() {
    //TODO
  }

  public void setNotifyOnRelease() {
    //TODO
  }

  public void setReleaseAgent() {
    //TODO
  }
}

@@ -151,16 +151,73 @@
 l.Shell;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -327,59 +327,8 @@
  %7B%0A%0A
-  protected Shell shell;%0A  protected Group group;%0A%0A
   pu
@@ -383,16 +383,334 @@
 COMMON;%0A
+  public static final String PROP_COMMON_EVENT_CONTROL = %22cgroup.event_control%22;%0A  public static final String PROP_COMMON_NOTIFY_ON_RELEASE =%0A      %22notify_on_release%22;%0A  public static final String PROP_COMMON_RELEASE_AGENT = %22release_agent%22;%0A  private static final Logger LOG = LoggerFactory.getLogger(Common.class);%0A
   public
@@ -761,16 +761,66 @@
 eger%3E();
+%0A  protected Shell shell;%0A  protected Group group;
 %0A%0A  publ
@@ -1310,125 +1310,1002 @@
 rol(
-) %7B%0A    //TODO%0A  %7D%0A%0A  public void setNotifyOnRelease() %7B%0A    //TODO%0A  %7D%0A%0A  public void setReleaseAgent() %7B%0A    //TODO
+String eventFd, String controlFd, String... args)%0A      throws IOException %7B%0A    StringBuilder sb = new StringBuilder();%0A    sb.append(eventFd);%0A    sb.append(' ');%0A    sb.append(controlFd);%0A    for (String arg : args) %7B%0A      sb.append(' ');%0A      sb.append(arg);%0A    %7D%0A%0A    shell.cgset(group.getName(), PROP_COMMON_EVENT_CONTROL, sb.toString());%0A  %7D%0A%0A  public void setNotifyOnRelease(boolean flag) throws IOException %7B%0A    int value = flag? 1 : 0;%0A    shell.cgset(group.getName(), PROP_COMMON_NOTIFY_ON_RELEASE, value + %22%22);%0A  %7D%0A%0A  public boolean isNotifyOnRelease() throws IOException %7B%0A    int output = Integer.getInteger(shell.cgget(group.getName(), PROP_COMMON_NOTIFY_ON_RELEASE));%0A    return output %3E 0;%0A  %7D%0A%0A  public void setReleaseAgent(String cmd) throws IOException %7B%0A    shell.cgset(group.getName(), PROP_COMMON_RELEASE_AGENT, cmd);%0A  %7D%0A%0A  public String getReleaseAgent() throws IOException %7B%0A    String cmd = shell.cgget(group.getName(), PROP_COMMON_RELEASE_AGENT);%0A    return cmd;
 %0A  %7D

Complete TODO items in Common.java