Source Code Cross Referenced for ATParticipant.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » tx » at » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » wsit » com.sun.xml.ws.tx.at 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:        package com.sun.xml.ws.tx.at;
037:
038:        import com.sun.xml.ws.api.SOAPVersion;
039:        import com.sun.xml.ws.api.addressing.AddressingVersion;
040:        import com.sun.xml.ws.api.addressing.OneWayFeature;
041:        import com.sun.xml.ws.api.addressing.WSEndpointReference;
042:        import com.sun.xml.ws.api.tx.Participant;
043:        import com.sun.xml.ws.api.tx.Protocol;
044:        import com.sun.xml.ws.api.tx.TXException;
045:        import com.sun.xml.ws.developer.MemberSubmissionEndpointReference;
046:        import com.sun.xml.ws.tx.common.AddressManager;
047:        import static com.sun.xml.ws.tx.common.Constants.WSAT_SOAP_NSURI;
048:        import com.sun.xml.ws.tx.common.StatefulWebserviceFactory;
049:        import com.sun.xml.ws.tx.common.StatefulWebserviceFactoryFactory;
050:        import com.sun.xml.ws.tx.common.TxLogger;
051:        import com.sun.xml.ws.tx.coordinator.Coordinator;
052:        import com.sun.xml.ws.tx.coordinator.Registrant;
053:        import com.sun.xml.ws.tx.webservice.member.at.CoordinatorPortType;
054:        import com.sun.xml.ws.tx.webservice.member.at.CoordinatorPortTypeImpl;
055:        import com.sun.xml.ws.tx.webservice.member.at.ParticipantPortType;
056:        import com.sun.xml.ws.tx.webservice.member.at.ParticipantPortTypeImpl;
057:        import com.sun.xml.ws.tx.webservice.member.coord.RegisterType;
058:
059:        import javax.transaction.xa.Xid;
060:        import javax.xml.namespace.QName;
061:        import javax.xml.soap.SOAPException;
062:        import javax.xml.soap.SOAPFault;
063:        import javax.xml.ws.EndpointReference;
064:        import javax.xml.ws.WebServiceException;
065:        import java.net.URI;
066:        import java.util.logging.Level;
067:
068:        /**
069:         * This class encapsulates a WS-AT participant.
070:         * <p/>
071:         * <p> A participant represents one of the three ws-at protocols:
072:         * completion, volatile 2PC or durable 2PC.
073:         * <p/>
074:         * <p> Participant lifecycle consist of generating a endpoint reference
075:         * <p/>
076:         * <p/>
077:         * Transaction timeout from Participants perspective.
078:         * Coordination Context expires  specifies the period, measured from
079:         * the point in time at which the context was first created or received, after which a
080:         * transaction MAY be terminated solely due to its length of operation.
081:         * A 2PC participant MAY elect to abort its work in the transaction so long as it has not
082:         * already decided to prepare.
083:         *
084:         * @author Ryan.Shoemaker@Sun.COM
085:         * @version $Revision: 1.16 $
086:         * @since 1.0
087:         */
088:        public class ATParticipant extends Registrant {
089:
090:            static public enum STATE {
091:                NONE, ACTIVE, PREPARING, PREPARED, PREPARED_SUCCESS, COMMITTING, ABORTING, COMMITTED, ABORTED, READONLY
092:            }
093:
094:            /* PPS */
095:            public static final URI LOCAL_PPS_URI = AddressManager
096:                    .getPreferredAddress(ParticipantPortType.class);
097:
098:            protected STATE state = STATE.NONE;
099:            protected Xid xid;
100:
101:            // Equivalent to an XAResource for WSAT
102:            private Participant participant = null;
103:            final private boolean remoteParticipant;
104:
105:            static private TxLogger logger = TxLogger
106:                    .getATLogger(ATParticipant.class);
107:            static final String WSAT_COORDINATOR = "WSATCoordinator";
108:
109:            private EndpointReference exportCoordinatorProtocolServiceForATParticipant(
110:                    final Coordinator coord) {
111:                return StatefulWebserviceFactoryFactory
112:                        .getInstance()
113:                        .createService(
114:                                WSAT_COORDINATOR,
115:                                "Coordinator",
116:                                ATCoordinator.localCoordinationProtocolServiceURI,
117:                                AddressingVersion.MEMBER, coord.getIdValue(),
118:                                this .getIdValue());
119:            }
120:
121:            /**
122:             * Register will figure out if participant will register with local or remote Coordination Protocol Service.
123:             */
124:            public ATParticipant(Coordinator parent, Participant participant) {
125:                super (parent, participant.getProtocol());
126:                this .participant = participant;
127:                this .remoteParticipant = false;
128:
129:                if (logger.isLogging(Level.FINEST)) {
130:                    logger.finest("ATParticipant", getCoordIdPartId());
131:                }
132:                // TODO: implement participant timeout from parent.getExpires().
133:            }
134:
135:            /**
136:             * Remote ATParticipant with a local Coordinator.
137:             * ParticipantProtocolService received as part of registerRequest.
138:             */
139:            public ATParticipant(Coordinator parent,
140:                    RegisterType registerRequest) {
141:                super (parent, registerRequest);
142:                if (logger.isLogging(Level.FINEST)) {
143:                    logger.finest("Remote ATParticipant", getCoordIdPartId());
144:                }
145:                participant = null;
146:                setCoordinatorProtocolService(exportCoordinatorProtocolServiceForATParticipant(parent));
147:                remoteParticipant = true;
148:                if (logger.isLogging(Level.FINEST)) {
149:                    logger.finest("Remote ATParticipant:", getCoordIdPartId()
150:                            + " CPS:" + getCoordinatorProtocolService());
151:                }
152:            }
153:
154:            public ParticipantPortType getParticipantPort(
155:                    final EndpointReference epr) {
156:                return ATCoordinator.getWSATCoordinatorService()
157:                        .getParticipant(epr);
158:            }
159:
160:            public boolean isVolatile() {
161:                return getProtocol() == Protocol.VOLATILE;
162:            }
163:
164:            public boolean isDurable() {
165:                return getProtocol() == Protocol.DURABLE;
166:            }
167:
168:            /**
169:             * A participant is forgotten after it has sent committed or aborted to coordinator.
170:             */
171:            public void forget() {
172:                if (isRemoteCPS() && localParticipantProtocolService != null) {
173:                    final ParticipantPortTypeImpl ppti = ParticipantPortTypeImpl
174:                            .getManager().resolve(
175:                                    localParticipantProtocolService);
176:
177:                    // could resolve to null if stateful webservice timeout already unexported automatically.
178:                    if (ppti != null) {
179:                        ParticipantPortTypeImpl.getManager().unexport(ppti);
180:                    }
181:                }
182:                localParticipantProtocolService = null;
183:                if (remoteParticipant) {
184:                    final CoordinatorPortTypeImpl cpti = CoordinatorPortTypeImpl
185:                            .getManager().resolve(
186:                                    getCoordinatorProtocolService());
187:                    if (cpti != null) {
188:                        CoordinatorPortTypeImpl.getManager().unexport(cpti);
189:                    }
190:                }
191:
192:                getATCoordinator().forget(this );
193:            }
194:
195:            private CoordinatorPortType getATCoordinatorWS(
196:                    final boolean nonterminalNotify) {
197:                if (getCoordinatorProtocolService() == null
198:                        && !isRegistrationCompleted()) {
199:                    logger.warning("getATCoordinatorWS", LocalizationMessages
200:                            .NO_REG_RESP_0014(getATCoordinator().getContext()
201:                                    .getRootRegistrationService().toString(),
202:                                    getCoordIdPartId()));
203:                }
204:
205:                return getATCoordinatorWS(getCoordinatorProtocolService(),
206:                        getParticipantProtocolService(), nonterminalNotify);
207:            }
208:
209:            public static CoordinatorPortType getATCoordinatorWS(
210:                    final EndpointReference toCPS,
211:                    final EndpointReference replyToPPS,
212:                    final boolean nonterminalNotify) {
213:                final OneWayFeature owf = new OneWayFeature();
214:                WSEndpointReference wsepr = null;
215:                if (nonterminalNotify && replyToPPS != null) {
216:                    try {
217:                        wsepr = new WSEndpointReference(replyToPPS);
218:                    } catch (Exception xse) {
219:                        logger
220:                                .severe(
221:                                        "getATCoordinatorWS",
222:                                        LocalizationMessages
223:                                                .REPLYTOPPS_EPR_EXCEPTION_0015(
224:                                                        replyToPPS.toString(),
225:                                                        xse
226:                                                                .getLocalizedMessage()));
227:                    }
228:                    if (wsepr != null) {
229:                        owf.setReplyTo(wsepr);
230:                    } else {
231:                        logger.warning("getATCoordinatorWS",
232:                                LocalizationMessages
233:                                        .NULL_PPS_EPR_WARNING_0016());
234:                    }
235:                }
236:                assert toCPS != null;
237:                return ATCoordinator.getWSATCoordinatorService()
238:                        .getCoordinator(toCPS, owf);
239:            }
240:
241:            private ParticipantPortType getATParticipantWS(
242:                    final boolean nonterminalNotification) {
243:                return this .getATParticipantWS(this 
244:                        .getParticipantProtocolService(), this 
245:                        .getCoordinatorProtocolService(),
246:                        nonterminalNotification);
247:            }
248:
249:            public static ParticipantPortType getATParticipantWS(
250:                    final EndpointReference toPPS,
251:                    final EndpointReference replyToCPS,
252:                    final boolean nonterminalNotification) {
253:                final OneWayFeature owf = new OneWayFeature();
254:                WSEndpointReference wsepr = null;
255:                if (nonterminalNotification && replyToCPS != null) {
256:                    try {
257:                        wsepr = new WSEndpointReference(replyToCPS);
258:                    } catch (Exception xse) {
259:                        logger
260:                                .severe(
261:                                        "getATCoordinatorWS",
262:                                        LocalizationMessages
263:                                                .REPLYTOPPS_EPR_EXCEPTION_0015(
264:                                                        replyToCPS.toString(),
265:                                                        xse
266:                                                                .getLocalizedMessage()));
267:                    }
268:                    if (wsepr != null) {
269:                        owf.setReplyTo(wsepr);
270:                    } else {
271:                        logger.warning("getATParticipantWS",
272:                                LocalizationMessages
273:                                        .NULL_CPS_EPR_WARNING_0018());
274:                    }
275:
276:                }
277:                assert toPPS != null;
278:                return ATCoordinator.getWSATCoordinatorService()
279:                        .getParticipant(toPPS, owf);
280:            }
281:
282:            public ATCoordinator getATCoordinator() {
283:                return (ATCoordinator) getCoordinator();
284:            }
285:
286:            /**
287:             * Return participant's state for Atomic Transaction 2PC Protocol.
288:             */
289:            public ATParticipant.STATE getState() {
290:                return state;
291:            }
292:
293:            protected Xid getXid() {
294:                return xid;
295:            }
296:
297:            /**
298:             * Returns participant state. or (something for abort).
299:             */
300:            public void prepare() throws TXException {
301:                final String METHOD_NAME = "prepare";
302:
303:                if (logger.isLogging(Level.FINER)) {
304:                    logger.entering(METHOD_NAME, "coordId="
305:                            + getCoordinator().getIdValue() + " partId="
306:                            + getIdValue());
307:                }
308:                switch (getState()) {
309:                case NONE:
310:                case ABORTING:
311:                    abort();
312:                    throw new TXException("Rollback");
313:
314:                case ACTIVE:
315:                    internalPrepare();
316:                    break;
317:
318:                case PREPARED_SUCCESS:
319:                    // just resend
320:                    if (isRemoteCPS()) {
321:                        try {
322:                            getATCoordinatorWS(true).preparedOperation(null);
323:                        } catch (WebServiceException wse) {
324:                            logger.warning(METHOD_NAME, LocalizationMessages
325:                                    .PREPARE_FAILED_0010(wse
326:                                            .getLocalizedMessage()));
327:
328:                            throw wse;
329:                        } catch (Exception e) {
330:                            logger.severe(METHOD_NAME, LocalizationMessages
331:                                    .PREPARE_FAILED_0010(e
332:                                            .getLocalizedMessage()));
333:                        }
334:                    } else {
335:                        getATCoordinator().prepared(getIdValue());
336:                    }
337:                    break;
338:
339:                case PREPARING:
340:                case PREPARED:
341:                case COMMITTING:
342:                    // ignore PREPARE in these states
343:                    break;
344:                }
345:                if (logger.isLogging(Level.FINER)) {
346:                    logger.exiting(METHOD_NAME, "coordId="
347:                            + getCoordinator().getIdValue() + " partId="
348:                            + getIdValue());
349:                }
350:            }
351:
352:            private void internalPrepare() throws TXException {
353:                if (remoteParticipant) {
354:                    remotePrepare();
355:                } else {
356:                    localPrepare();
357:                }
358:            }
359:
360:            private void remotePrepare() {
361:                state = STATE.PREPARING;
362:                // TODO: resend if don't receive prepared notfication from coordinator in some communication timeout amount of time
363:                try {
364:                    getATParticipantWS(true).prepareOperation(null);
365:                } catch (WebServiceException wse) {
366:                    logger.warning("remotePrepare", LocalizationMessages
367:                            .PREPARE_FAILED_0010(wse.getLocalizedMessage()));
368:                    throw wse;
369:                } catch (Exception e) {
370:                    logger.severe("remotePrepare", LocalizationMessages
371:                            .PREPARE_FAILED_0010(e.getLocalizedMessage()));
372:                }
373:            }
374:
375:            private void localPrepare() throws TXException {
376:                final String METHOD_NAME = "localPrepare";
377:                if (logger.isLogging(Level.FINER)) {
378:                    logger.entering(METHOD_NAME, getCoordIdPartId());
379:                }
380:                Participant.STATE result = null;
381:                state = STATE.PREPARING;
382:                try {
383:                    result = participant.prepare();
384:                } catch (TXException e) {
385:                    // failure during prepare, just abort
386:
387:                    // set participant to null. don't want to call its abort(), it already knows its aborted
388:                    participant = null;
389:                    abort();
390:                    throw new TXException("Rollback");
391:                } catch (Exception e) {
392:                    participant = null;
393:                    abort();
394:                    throw new TXException("Rollback");
395:                }
396:                switch (result) {
397:                case P_OK:
398:                    state = STATE.PREPARED;
399:                    if (isRemoteCPS()) {
400:                        if (logger.isLogging(Level.FINEST)) {
401:                            logger.finest(METHOD_NAME,
402:                                    "send prepared to remote coordinator"
403:                                            + getIdValue());
404:                        }
405:                        try {
406:                            getATCoordinatorWS(true).preparedOperation(null);
407:                        } catch (WebServiceException wse) {
408:                            logger.warning(METHOD_NAME, LocalizationMessages
409:                                    .PREPARE_FAILED_0010(wse
410:                                            .getLocalizedMessage()));
411:                            throw wse;
412:                        }
413:                    } else {
414:                        if (logger.isLogging(Level.FINEST)) {
415:                            logger.finest(METHOD_NAME,
416:                                    "send prepared to local coordinator"
417:                                            + getIdValue());
418:                        }
419:                        getATCoordinator().prepared(this .getIdValue());
420:                    }
421:                    state = STATE.PREPARED_SUCCESS;
422:                    break;
423:
424:                case P_READONLY:
425:                    state = STATE.READONLY;
426:                    if (isRemoteCPS()) {
427:                        if (logger.isLogging(Level.FINEST)) {
428:                            logger.finest(METHOD_NAME,
429:                                    "send readonly to remote coordinator for participant id"
430:                                            + getIdValue());
431:                        }
432:                        try {
433:                            getATCoordinatorWS(false).readOnlyOperation(null);
434:                        } catch (WebServiceException wse) {
435:                            logger.warning(METHOD_NAME,
436:                                    "readonly to web service failed. "
437:                                            + wse.getLocalizedMessage());
438:                            throw wse;
439:                        }
440:                    } else {
441:                        if (logger.isLogging(Level.FINEST)) {
442:                            logger.finest(METHOD_NAME,
443:                                    "send readonly to remote coordinator for participant id"
444:                                            + getIdValue());
445:                        }
446:                        getATCoordinator().readonly(getIdValue());
447:                    }
448:                    if (logger.isLogging(Level.FINE)) {
449:                        logger.fine(METHOD_NAME, "readonly "
450:                                + getCoordIdPartId());
451:                    }
452:                    forget();
453:                    break;
454:                }
455:                if (logger.isLogging(Level.FINER)) {
456:                    logger.exiting("ATParticipant.localPrepare");
457:                }
458:            }
459:
460:            /**
461:             * Send Terminal notification
462:             */
463:            private void remoteCommit() {
464:                // TODO: resend if don't receive committed notification from coordinator in some communication timeout amount of time
465:
466:                if (logger.isLogging(Level.FINER)) {
467:                    logger.entering("remoteCommit()", getIdValue());
468:                }
469:                this .getATParticipantWS(true).commitOperation(null);
470:                if (logger.isLogging(Level.FINER)) {
471:                    logger.exiting("remoteCommit");
472:                }
473:            }
474:
475:            public void commit() throws TXException {
476:                if (logger.isLogging(Level.FINER)) {
477:                    logger.entering("commit" + getCoordIdPartId());
478:                }
479:                if (remoteParticipant) {
480:                    remoteCommit();
481:                } else {
482:                    localCommit();
483:                }
484:                if (logger.isLogging(Level.FINER)) {
485:                    logger.entering("commit" + getCoordIdPartId());
486:                }
487:            }
488:
489:            private void localCommit() {
490:                final String METHOD_NAME = "localCommit";
491:                switch (getState()) {
492:                case NONE:
493:
494:                    // TODO send committed using wsa:replyTo EPR.
495:                    // this case
496:                    break;
497:                case ABORTING:
498:                    logger.warning(METHOD_NAME, LocalizationMessages
499:                            .INCONSISTENT_STATE_0020(getState(),
500:                                    getCoordIdPartId()));
501:                    //fault wsat:InconsistentInternalState
502:                    abort();
503:
504:                    break;
505:                case ACTIVE:
506:                case PREPARING:
507:                case PREPARED:
508:                    logger.warning(METHOD_NAME, LocalizationMessages
509:                            .INCONSISTENT_STATE_0020(getState(),
510:                                    getCoordIdPartId()));
511:                    // TODO throw fault coor:InvalidState
512:                    abort();
513:                    break;
514:
515:                case PREPARED_SUCCESS:
516:                    state = STATE.COMMITTING;
517:                    participant.commit();
518:                    participant = null; // no longer need to contact participant.
519:                    if (logger.isLogging(Level.FINE)) {
520:                        logger.fine(METHOD_NAME, "committed "
521:                                + getCoordIdPartId());
522:                    }
523:                    if (isRemoteCPS()) {
524:                        try {
525:                            getATCoordinatorWS(false).committedOperation(null);
526:                        } catch (WebServiceException wse) {
527:                            logger.warning(METHOD_NAME, LocalizationMessages
528:                                    .COMMITTED_FAILED_0021(wse
529:                                            .getLocalizedMessage()));
530:                            throw wse;
531:                        }
532:                    } else {
533:                        getATCoordinator().committed(getIdValue());
534:                    }
535:                    forget();
536:                    break;
537:
538:                case COMMITTING:
539:                    if (isRemoteCPS()) {
540:                        getATCoordinatorWS(false).committedOperation(null);
541:                    } else {
542:                        getATCoordinator().committed(getIdValue());
543:                    }
544:                    forget();
545:
546:                    break;
547:                }
548:            }
549:
550:            public void abort() {
551:                if (logger.isLogging(Level.FINER)) {
552:                    logger.entering("abort", getCoordIdPartId());
553:                }
554:
555:                //TODO. put switch statement over all possible 2pc transaction state.
556:                //      invalid states require fault to be sent
557:
558:                state = STATE.ABORTING;
559:
560:                // local rollback
561:                if (participant != null) {
562:                    participant.abort();
563:                    participant = null; // no need to contact participant anymore
564:                }
565:                // pass rollback to remote participant
566:                if (remoteParticipant) {
567:                    remoteRollback();
568:                } else {
569:                    localRollback();
570:                }
571:
572:                if (logger.isLogging(Level.FINER)) {
573:                    logger.exiting("abort", getCoordIdPartId());
574:                }
575:            }
576:
577:            private void localRollback() {
578:                if (isRemoteCPS()) {
579:                    try {
580:                        getATCoordinatorWS(false).abortedOperation(null);
581:                    } catch (WebServiceException wse) {
582:                        logger.warning("localRollback",
583:                                LocalizationMessages.PREPARED_FAILED_0019(wse
584:                                        .getLocalizedMessage()));
585:                        throw wse;
586:                    }
587:                } else {
588:                    getATCoordinator().aborted(getIdValue());
589:                }
590:
591:                if (logger.isLogging(Level.FINE)) {
592:                    logger.fine("abort", getCoordIdPartId());
593:                }
594:                forget();
595:            }
596:
597:            /**
598:             * Send terminal notification
599:             */
600:            private void remoteRollback() {
601:                // TODO: resend if don't receive aborted notification from coordinator in some communication timeout amount of time
602:
603:                if (logger.isLogging(Level.FINER)) {
604:                    logger.entering("remoteRollack", getCoordIdPartId());
605:                }
606:                getATParticipantWS(true).rollbackOperation(null);
607:                if (logger.isLogging(Level.FINER)) {
608:                    logger.exiting("remoteRollback", getCoordIdPartId());
609:                }
610:            }
611:
612:            public void setCoordinatorProtocolService(
613:                    final EndpointReference cps) {
614:                super .setCoordinatorProtocolService(cps);
615:
616:                if (cps != null) {
617:                    // wscoor:registerResponse successfully communicated CPS, change participant's state
618:                    state = STATE.ACTIVE;
619:                }
620:            }
621:
622:            void prepared() {
623:                // TODO:  given current state, check if it is valid to set to this state.
624:                state = STATE.PREPARED_SUCCESS;
625:                if (logger.isLogging(Level.FINE)) {
626:                    logger.fine("prepared", this .getCoordIdPartId() + " STATE="
627:                            + state.toString());
628:                }
629:            }
630:
631:            void committed() {
632:                // TODO: verify state transition does not need to throw invalid state fault.
633:                state = STATE.COMMITTED;
634:                if (logger.isLogging(Level.FINE)) {
635:                    logger.fine("committed", this .getCoordIdPartId()
636:                            + " STATE=" + state.toString());
637:                }
638:            }
639:
640:            void readonly() {
641:                // TODO: verify state transition does not need to throw invalid state fault.
642:                state = STATE.READONLY;
643:                if (logger.isLogging(Level.FINE)) {
644:                    logger.fine("readonly", this .getCoordIdPartId() + " STATE="
645:                            + state.toString());
646:                }
647:            }
648:
649:            void aborted() {
650:                // TODO: verify state transition does not need to throw invalid state fault.
651:                state = STATE.ABORTED;
652:                if (logger.isLogging(Level.FINE)) {
653:                    logger.fine("aborted", this .getCoordIdPartId() + " STATE="
654:                            + state.toString());
655:                }
656:            }
657:
658:            /**
659:             * This fault is sent by a participant to indicate that it cannot fulfill its obligations.
660:             * This indicates a global consistency failure and is an unrecoverable condition.
661:             *
662:             * @param soapVersion SOAP verion for returned fault.
663:             */
664:            /*
665:            private Packet newInconsistentInternalStateFault(final SOAPVersion soapVersion, final String detail) {
666:                Packet faultResponsePacket = null;
667:                // wsa:Action Constants.WSAT_FAULT_ACTION_URI
668:                // [Code] Sender
669:                // [Subcode] wsat:InconsistentInternalState
670:                // [Reason] A global consistency failure has occurred. This is an unrecoverable condition.
671:                // [Detail] detail
672:                throw new UnsupportedOperationException("Not implemented yet");
673:            }
674:             */
675:
676:            /**
677:             * @see com.sun.xml.ws.tx.common.WsaHelper
678:             * @deprecated since now
679:             */
680:            SOAPFault createSOAPFault(final String message) {
681:                try {
682:                    final SOAPFault fault = SOAPVersion.SOAP_11.saajSoapFactory
683:                            .createFault();
684:                    fault.setFaultString(message);
685:                    // TODO: fix deprecated constant reference
686:                    // fault.setFaultCode(JAXWSAConstants.SOAP11_SENDER_QNAME);
687:                    fault.appendFaultSubcode(new QName(WSAT_SOAP_NSURI,
688:                            "InconsistentInternalState"));
689:                    fault
690:                            .setFaultRole("A global consistent failure has occurred. This is an unrecoverable condition.");
691:                    return fault;
692:                } catch (SOAPException ex) {
693:                    throw new WebServiceException(ex);
694:                }
695:            }
696:
697:            private String getCoordIdPartId() {
698:                return " coordId=" + getCoordinator().getIdValue() + " partId="
699:                        + getIdValue() + " ";
700:            }
701:
702:            private EndpointReference localParticipantProtocolService = null;
703:
704:            /**
705:             * No need to export an external stateful web service for this usage case.
706:             */
707:            public EndpointReference getLocalParticipantProtocolService() {
708:                if (localParticipantProtocolService == null) {
709:                    if (isRemoteCPS()) {
710:                        final StatefulWebserviceFactory swf = StatefulWebserviceFactoryFactory
711:                                .getInstance();
712:                        localParticipantProtocolService = swf.createService(
713:                                WSAT_COORDINATOR, "Participant", LOCAL_PPS_URI,
714:                                AddressingVersion.MEMBER, getATCoordinator()
715:                                        .getIdValue(), this .getId().getValue());
716:                    } else {
717:                        localParticipantProtocolService = getLocalParticipantProtocolServiceEPR();
718:                    }
719:                }
720:                return localParticipantProtocolService;
721:            }
722:
723:            static public EndpointReference getLocalParticipantProtocolServiceEPR() {
724:                final MemberSubmissionEndpointReference epr = new MemberSubmissionEndpointReference();
725:                epr.addr = new MemberSubmissionEndpointReference.Address();
726:                epr.addr.uri = LOCAL_PPS_URI.toString();
727:                return epr;
728:            }
729:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.