1 24 25 package org.objectweb.cjdbc.controller.virtualdatabase.protocol; 26 27 import java.sql.SQLException ; 28 29 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException; 30 import org.objectweb.cjdbc.common.i18n.Translate; 31 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest; 32 import org.objectweb.cjdbc.controller.loadbalancer.AllBackendsFailedException; 33 import org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager; 34 35 41 public class ExecWriteRequest extends DistributedRequest 42 { 43 private static final long serialVersionUID = -4849018153223926739L; 44 private int numberOfEnabledBackends; 45 46 49 public ExecWriteRequest(AbstractWriteRequest request) 50 { 51 super(request); 52 } 53 54 57 public void scheduleRequest(DistributedRequestManager drm) 58 throws SQLException 59 { 60 drm.scheduleExecWriteRequest((AbstractWriteRequest) request); 62 } 63 64 67 public Object executeScheduledRequest(DistributedRequestManager drm) 68 throws SQLException 69 { 70 numberOfEnabledBackends = drm.getLoadBalancer() 71 .getNumberOfEnabledBackends(); 72 73 try 74 { 75 int execWriteRequestResult = 0; 76 if (numberOfEnabledBackends == 0) 77 throw new NoMoreBackendException( 78 "No backend enabled on this controller"); 79 execWriteRequestResult = drm 80 .loadBalanceExecWriteRequest((AbstractWriteRequest) request); 81 drm.updateAndNotifyExecWriteRequest((AbstractWriteRequest) request); 82 return new Integer (execWriteRequestResult); 83 } 84 catch (NoMoreBackendException e) 85 { 86 if (drm.getLogger().isDebugEnabled()) 87 drm.getLogger().debug( 88 Translate.get("virtualdatabase.distributed.write.logging.only", 89 request.getSQLShortForm(drm.getVirtualDatabase() 90 .getSQLShortFormLength()))); 91 92 if (drm.getRecoveryLog() != null) 95 { 96 if (numberOfEnabledBackends == 0) 97 { if (drm.getLoadBalancer().waitForTotalOrder(request, false)) 99 drm.getLoadBalancer().removeHeadFromAndNotifyTotalOrderQueue(); 100 } 101 long logId = drm.getRecoveryLog().logRequest( 102 (AbstractWriteRequest) request); 103 e.setRecoveryLogId(logId); 104 } 105 drm.getScheduler().writeCompleted((AbstractWriteRequest) request); 107 throw e; 108 } 109 catch (AllBackendsFailedException e) 110 { 111 drm.getScheduler().writeCompleted((AbstractWriteRequest) request); 114 drm.addFailedOnAllBackends(request); 115 if (drm.getLogger().isDebugEnabled()) 116 drm 117 .getLogger() 118 .debug( 119 Translate 120 .get( 121 "virtualdatabase.distributed.write.all.backends.locally.failed", 122 request.getSQLShortForm(drm.getVirtualDatabase() 123 .getSQLShortFormLength()))); 124 return e; 125 } 126 catch (SQLException e) 127 { 128 drm.getScheduler().writeCompleted((AbstractWriteRequest) request); 131 drm.getLogger().warn( 132 Translate.get("virtualdatabase.distributed.write.sqlexception", e 133 .getMessage()), e); 134 throw e; 135 } 136 catch (RuntimeException re) 137 { 138 drm.getScheduler().writeCompleted((AbstractWriteRequest) request); 141 drm.getLogger().warn( 142 Translate.get("virtualdatabase.distributed.write.exception", re 143 .getMessage()), re); 144 throw new SQLException (re.getMessage()); 145 } 146 } 147 148 } | Popular Tags |