/**
* Copyright © 2013 enioka. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.enioka.ui.controlers;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;
import com.enioka.jqm.api.JobInstance;
import com.enioka.jqm.api.JqmClientFactory;
import com.enioka.jqm.api.State;
@ManagedBean(eager = true)
@SessionScoped
public class ActiveQueueControler extends ListDataModel<JobInstance> implements Serializable, SelectableDataModel<JobInstance>
{
private static final long serialVersionUID = 7869898762565932002L;
private JobInstance selected = null;
public String stop()
{
if (selected.getState().equals(State.SUBMITTED))
{
JqmClientFactory.getClient().cancelJob(selected.getId());
}
else
{
JqmClientFactory.getClient().killJob(selected.getId());
}
return "queuecontent?faces-redirect=true";
}
public ListDataModel<JobInstance> getActiveJobs()
{
List<JobInstance> jis = JqmClientFactory.getClient().getActiveJobs();
this.setWrappedData(jis);
return this;
}
public JobInstance getSelected()
{
return selected;
}
public void setSelected(JobInstance selected)
{
this.selected = selected;
}
@Override
public Object getRowKey(JobInstance object)
{
return object.getId();
}
@Override
public JobInstance getRowData(String rowKey)
{
return JqmClientFactory.getClient().getJob(Integer.parseInt(rowKey));
}
}