Improve push notifications for request with device list less than batch size

revert-70aa11f8
warunalakshitha 8 years ago
parent 97a53a7387
commit 76f8d963f7

@ -40,6 +40,7 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -146,7 +147,12 @@ public class OperationManagerImpl implements OperationManager {
boolean isScheduledOperation = this.isTaskScheduledOperation(operation, deviceIds);
boolean isNotRepeated = false;
boolean isScheduled = false;
if (notificationStrategy != null) {
// check whether device list is greater than batch size notification strategy has enable to send push
// notification using scheduler task
if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getPushNotificationConfiguration().getSchedulerBatchSize() < authorizedDeviceList.size() &&
notificationStrategy != null) {
isScheduled = notificationStrategy.getConfig().isScheduled();
}
@ -178,8 +184,15 @@ public class OperationManagerImpl implements OperationManager {
} else {
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
}
if (notificationStrategy != null && !notificationStrategy.getConfig().isScheduled()) {
/*
If notification strategy has not enable to send push notification using scheduler task
we will send notification immediately
*/
if (notificationStrategy != null && !isScheduled) {
try {
if (log.isDebugEnabled()) {
log.debug("Sending push notification to " + deviceId + " add operation thread.");
}
notificationStrategy.execute(new NotificationContext(deviceId, operation));
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon
.device.mgt.core.dto.operation.mgt.Operation.PushStatus.COMPLETED);

@ -15,9 +15,10 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.operation.mgt;
package org.wso2.carbon.device.mgt.core.operation.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
/**
* Class for represent operation mapping
@ -27,6 +28,8 @@ public class OperationMapping {
private DeviceIdentifier deviceIdentifier;
private int operationId;
private int tenantId;
private Operation.Status status;
private Operation.PushStatus pushStatus;
public int getOperationId() {
return operationId;
@ -51,4 +54,20 @@ public class OperationMapping {
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
public Operation.Status getStatus() {
return status;
}
public void setStatus(Operation.Status status) {
this.status = status;
}
public Operation.PushStatus getPushStatus() {
return pushStatus;
}
public void setPushStatus(Operation.PushStatus pushStatus) {
this.pushStatus = pushStatus;
}
}

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;

@ -18,7 +18,7 @@
*/
package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import java.util.List;
@ -31,7 +31,7 @@ public interface OperationMappingDAO {
void updateOperationMapping(int operationId, Integer deviceId, Operation.PushStatus pushStatus) throws
OperationManagementDAOException;
void updateOperationMapping(List<OperationMapping> operationMappingList, Operation.PushStatus pushStatus) throws
void updateOperationMapping(List<OperationMapping> operationMappingList) throws
OperationManagementDAOException;
}

@ -24,7 +24,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;

@ -18,8 +18,8 @@
*/
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
@ -98,7 +98,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
}
@Override
public void updateOperationMapping(List<OperationMapping> operationMappingList, Operation.PushStatus pushStatus) throws
public void updateOperationMapping(List<OperationMapping> operationMappingList) throws
OperationManagementDAOException {
PreparedStatement stmt = null;
try {
@ -108,7 +108,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
stmt = conn.prepareStatement(sql);
if (conn.getMetaData().supportsBatchUpdates()) {
for (OperationMapping operationMapping : operationMappingList) {
stmt.setString(1, pushStatus.toString());
stmt.setString(1, operationMapping.getPushStatus().toString());
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
stmt.setInt(3, operationMapping.getOperationId());
stmt.addBatch();
@ -116,7 +116,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
stmt.executeBatch();
} else {
for (OperationMapping operationMapping : operationMappingList) {
stmt.setString(1, pushStatus.toString());
stmt.setString(1, operationMapping.getPushStatus().toString());
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
stmt.setInt(3, operationMapping.getOperationId());
stmt.executeUpdate();

@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;

@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;

@ -23,7 +23,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
@ -84,6 +84,7 @@ public class PushNotificationJob implements Runnable {
notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(),
provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping
.getOperationId())));
operationMapping.setPushStatus(Operation.PushStatus.COMPLETED);
operationsCompletedList.add(operationMapping);
} catch (DeviceManagementException e) {
log.error("Error occurred while getting notification strategy for operation mapping " +
@ -109,7 +110,7 @@ public class PushNotificationJob implements Runnable {
// Update push notification status to competed for operations which already sent
try {
OperationManagementDAOFactory.beginTransaction();
operationMappingDAO.updateOperationMapping(operationsCompletedList, Operation.PushStatus.COMPLETED);
operationMappingDAO.updateOperationMapping(operationsCompletedList);
OperationManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException | OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();

Loading…
Cancel
Save